php - set multiple='false' in a form in a many to many relation symfony2 -
i have many-to-many relationship between 2 entities , b.
so when adding form, in order add entitya entityb, doing following:
$builder ->add('entityas', 'entity', array( 'class' => 'xxxbundle:entitya', 'property' => 'name', 'multiple' => true, ));} and alright.
but depending on field type of entitya, want set 'multiple' false, i'm doing following :
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, )); } this gives me following error:
catchable fatal error: argument 1 passed doctrine\common\collections\arraycollection::__construct() must array, object given, called in c:\wamp\www\symfony\vendor\doctrine\orm\lib\doctrine\orm\unitofwork.php on line 519 , defined in c:\wamp\www\symfony\vendor\doctrine\common\lib\doctrine\common\collections\arraycollection.php line 48 can me?
in entitya, have this, right?
public function setentitiesb($data) { $this->entitiesb = $data ; } now because can receive single value instead of array of values, need this:
public function setentitiesb($data) { if ( is_array($data) ) { $this->entitiesb = $data ; } else { $this->entitiesb->clear() ; $this->entitiesb->add($data) ; } }
Comments
Post a Comment