形式“假”我有两个实体A和B.设置多个=在多对多的关系Symfony2的
所以加入表单时之间的许多一对多的关系,为了增加entityA
到entityB
,我做了以下内容:
$builder
->add('entityAs', 'entity', array(
'class' => 'xxxBundle:EntityA',
'property' => 'name',
'multiple' => true,
));}
而且一切正常。
但根据字段类型entityA的,我想有时设置“多”为假,所以我做了以下内容:
if($type=='a'){
$builder
->add('entityAs', 'entity', array(
'class' => 'xxxBundle:entityA',
'property' => 'name',
'multiple' => true,
));}
else {
$builder
->add('entityAs', 'entity', array(
'class' => 'xxxBundle:entityA',
'property' => 'name',
'multiple' => false,
));
}
这给了我下面的错误:
Catchable Fatal Error: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be an array, object given, called in C:\wamp\www\Symfony\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 519 and defined in C:\wamp\www\Symfony\vendor\doctrine\common\lib\Doctrine\Common\Collections\ArrayCollection.php line 48
任何人都可以帮助我吗?
你确定错误是在这里提出? – DonCallisto 2013-05-14 09:19:33
其实是@DonCallisto – user2269869 2013-05-14 09:21:07
我敢打赌不。我敢打赌,错误是进入你的实体:你期望有一个ArrayCollection,但你有一个单一的实体(对象),这会导致你的问题。 – DonCallisto 2013-05-14 09:36:17