pu a multiplie => false を多対多関係にしようとしましたが、このエラーが発生しました。
Expected an object, but got a collection. Did you forget to pass
エンティティ フィールドに "multiple=true" ?
だから解決策を見つけましたが、他のエラーがあります。
Catchable Fatal Error: Argument 1 passed to Plop\PlipBundle\Form\{closure}() must be an instance of Plop\PlipBundle\Form\Collection, null given in /var/www/Symfony/src/plop/plipBundle/Form/CampaignSupportType.php line 22
そして私のコードです:
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add(
$builder->create('supports', 'entity', array(
'class' => 'PlopPlipBundle:Support','multiple' => false,
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('s')
->orderBy('s.name', 'ASC');
}, 'property' => 'name'))
->prependNormTransformer(new CallbackTransformer(
// transform the collection to its first element
function (Collection $coll) { return $coll[0]; },
// transform the element to a collection
function (MyEntity $entity) { return new ArrayCollection(array($entity)); }
))
);
}
編集
@bernhardの回答で、新しいエラーが発生しました:
Catchable Fatal Error: Argument 1 passed to Plop\PlipBundle\Form\{closure}() must be an instance of Plop\PlipBundle\Form\Collection, instance of Doctrine\Common\Collections\ArrayCollection given in /var/www/Symfony/src/plop/PlipBundle/Form/CampaignSupportType.php line 22
今は与えられた null ではありませんがDoctrine\Common\Collections\ArrayCollection
、Symfony2 は a を待ちますPlop\PlipBundle\Form\Collection
。