2014-01-20 1 views
1

내 프로젝트 중 하나에서 FOSUserBundle을 사용하고 있습니다.Symfony2 : Form이 Doctrine Common Collections ArrayCollection :: ArrayCollection에 전달 된 인수 1을 던졌습니다. __ construct()는 배열, 주어진 객체 여야합니다 "on submit

Employee 개체 (RoleGroup을 가진 manytomany)를 기반으로 양식을 작성했습니다. 어떻게 양식이를 반환 할 수 있습니다

at ErrorHandler ->handle ('4096', 'Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be an array, object given, called in /home/mihai/intranet/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 528 and defined', '/home/mihai/intranet/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php', '47', array()) 
in /home/mihai/intranet/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php at line 47 

: 나는 양식을 제출하면

$builder->add('groups', 'entity', array(
    'class' => 'MMAAuthBundle:RoleGroup', 
    'choices' => $this->groups, 
    'property' => 'name', 
    'label' => 'Groups', 
    'expanded' => true, 
    'attr' => array("multiple" => true) 
)); 

, 나는 프로파일에서이 오류가 발생합니다 : 여기

양식 (의 일부)입니다 ArrayCollection, 아니 RoleGroup 개체?

전 정확하게 this 문제가 있었지만 지금은 여기에 붙어 있습니다.

답변

3

양식 현재 하지 여러 형태이므로 대신 Collection의 생성자 RoleGroup 오브젝트의 배열의 단일 RoleGroup 객체를 전달한다.

multiple양식 옵션 ...이고 HTML 속성은 아닙니다. 따라서 ...

$builder->add('groups', 'entity', array(
// This would only render a multiple="true" inside the fields HTML tag 
'attr' => array("multiple" => true) 
... 마법처럼 작동

$builder->add('groups', 'entity', array(
// multiple option not wrapped by attribute is correct 
"multiple" => true 
+0

가, 감사합니다 ...해야합니다! – MihaiM

관련 문제