2013-02-10 4 views
0

FOSUserBundle의 등록 양식을 다른 양식에 통합하고자합니다. 내 단체 "Anagrafic"과 일대 다 관계를 맺었 기 때문입니다. 코드 :FOSUserBundle 양식을 다른 양식에 등록

AnagraficType.php 

->add('utenze', new \FOS\UserBundle\Form\Type\RegistrationFormType($builder)) 

그러나 오류를 반환합니다. 어떻게해야합니까?

편집 : 좋아 .. 그래서 문제 .. 해결하고 :

->add('utenze', new \My\UserBundle\Form\Type\RegistrationFormType('\My\UserBundle\Entity\User')) 

그러나 나는이 오류를 얻을 :이 오류가 발생되는 이유는 무엇

The form's view data is expected to be an instance of class \My\UserBundle\Entity\User, 
but is an instance of class Doctrine\Common\Collections\ArrayCollection. 
You can avoid this error by setting the "data_class" option to null or by adding a view 
transformer that transforms an instance of class 
Doctrine\Common\Collections\ArrayCollection to an instance of \My\UserBundle\Entity\User. 

를? 나는 "널 (null)"다음 교리의 장점을하지 않는하려면 "data_class"을 설정하면 .. 나의 관계는 다음과 같습니다

class Anagrafic 
{ 
    //.. 
    /** 
    * @ORM\OneToMany(targetEntity="My\UserBundle\Entity\User", mappedBy="anagrafic") 
    */ 
    private $utenze; 

    public function __construct() 
    { 
    $this->utenze = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 
***** 
class User extends BaseUser 
{ 
    //.. 
    /** 
* @ORM\ManyToOne(targetEntity="My\BusinessBundle\Entity\Anagrafic", inversedBy="utenze") 
* @ORM\JoinColumn(name="anagrafic_id", referencedColumnName="id") 
*/ 
private $anagrafic; 

문제점은 무엇입니까?

답변

0

좋아, 해결책을 찾았습니다.

->add('utenze', 'collection', array('type' => new \My\UserBundle\Form\Type\RegistrationFormType('\My\UserBundle\Entity\User'))) 

대신

->add('utenze', new \My\UserBundle\Form\Type\RegistrationFormType('\My\UserBundle\Entity\User'))