我从互联网上搜索答案,但找不到原因:我有一家表公司,表公司类型,所以:
/**
* Acme\UserBundle\Entity\Company
*
* @ORM\Table(name="company")
* @ORM\Entity
*/
class Company
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var CompanyType
*
* @ORM\ManyToOne(targetEntity="CompanyType")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="company_type_id", referencedColumnName="id")
* })
*/
private $companyType;
...
}
/**
* Acme\UserBundle\Entity\CompanyType
*
* @ORM\Table(name="company_type")
* @ORM\Entity
*/
class CompanyType
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=45, nullable=true)
*/
private $name;
....
public function __toString(){
return $this->name;
}
}
然后,在 formtype 类中:
class CompanyForm extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('name')
->add('siren')
->add('siret')
->add('tvaCommun')
->add('apeCode')
;
$builder->add('activity','collection', array('type'=> new ActivityForm()));
$builder->add('companyType','entity',array(
'class' => 'AcmeUserBundle:CompanyType',
));
}
...
}
当我尝试使用表格时:
{{ form_row(company.companyType) }}
在视图中,我收到了错误消息。