2012-03-04 6 views
1

나는 지금은 일대 다 관계를 만들려면 두 기관
UserPhotoSymfony2 관계 두 엔티티, ArrayCollection에

을 만들었습니다.

// User.php 
    /** 
    * @ORM\OneToMany(targetEntity="Photo", mappedBy="user") 
    */ 
    protected $photos; 

    public function __construct() 
    { 
     $this->photos = new ArrayCollection(); 
    } 

전 유사가이 코드를 어떻게하는지에, 사용자의 형태로 사진의 양식을 추가

// UserType.php 
    public function buildForm(FormBuilder $builder, array $options) 
    { 
     // ... 
     $builder->add('photos', new PhotoType()); 
    } 

가 발생합니다 :
내가 User 엔티티 클래스에서이 코드가 있다고 가정

Expected argument of type "Acme\UserBundle\Entity\Photo", "Doctrine 
\Common\Collections\ArrayCollection" given 

어떻게 사용자의 양식에 사진의 양식을 추가 할 수 있습니까? 대한

PS 미안 내 영어

+0

분자 : 당신은 포토 타이프의 컬렉션을해야합니까? 내가 뭐라 구요? –

답변

3

당신은 당신의 폼 빌더 착각 : 내가 uderstand하지

$builder->add('photos', 'collection', array('type' => new PhotoType()));

+0

symony 3의 "type"에 해당하는 것은 무엇입니까? –