保存表单时我得到了这个。
Object of class Business\CompaniesBundle\Model\Province could not be converted to int in /Library/WebServer/Documents/business/src/Business/CompaniesBundle/Model/om/BaseCompany.php
<?php
namespace Business\CompaniesBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Business\CompaniesBundle\Model\IndustriesQuery;
use Business\CompaniesBundle\Model\Province;
use Business\CompaniesBundle\Model\ProvinceQuery;
class CompanyType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('company_name');
$builder->add('company_description','textarea');
$builder->add('company_address');
$builder->add('province_id', 'model', array(
'class'=>'Business\CompaniesBundle\Model\Province'
//'query'=> ProvinceQuery::create()->orderByProvinceName()
));
$builder->add('industries', 'model', array(
'class'=>'Business\CompaniesBundle\Model\Industries',
'query'=> IndustriesQuery::create()->orderByIndustryName(),
'multiple'=>true,
'expanded'=>true,
'required'=>true
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array('data_class'=>'Business\CompaniesBundle\Model\Company'));
}
public function getName() {
return 'company';
}
知道这里的问题是什么?
答案 0 :(得分:0)
通过更改
来修复它$builder->add('province_id', 'model', array(
'class'=>'Business\CompaniesBundle\Model\Province'
));
到
$builder->add('province', 'model', array(
'class'=>'Business\CompaniesBundle\Model\Province'
));
Company对象的setProvince方法需要省类型
的对象