Symfony FOSUserBundle表单在另一个表单中注册

Symfony FOSUserBundle表单在另一个表单中注册,symfony,symfony-2.1,fosuserbundle,Symfony,Symfony 2.1,Fosuserbundle,我想将FOSUserBundle的注册表格整合到另一个表格中。 这是因为我与我的实体“Anagrafic”建立了一对多的关系 代码如下: AnagraficType.php ->add('utenze', new \FOS\UserBundle\Form\Type\RegistrationFormType($builder)) 但是返回一个错误。 我该怎么做 编辑: 好啊这样,问题就解决了 ->add('utenze', new \My\UserBundle\Form\Type\

我想将FOSUserBundle的注册表格整合到另一个表格中。 这是因为我与我的实体“Anagrafic”建立了一对多的关系 代码如下:

AnagraficType.php

->add('utenze', new \FOS\UserBundle\Form\Type\RegistrationFormType($builder))
但是返回一个错误。 我该怎么做

编辑: 好啊这样,问题就解决了

->add('utenze', new \My\UserBundle\Form\Type\RegistrationFormType('\My\UserBundle\Entity\User'))
->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.
为什么我会收到这个错误? 如果我将“data_class”设置为“null”,那么就不要利用条令的好处。。 我的关系是:

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;

怎么了?

好的,我找到了解决办法

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