0

我想以另一种形式集成 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'))

但我得到这个错误:

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”,那么不要利用 Doctrine 的好处。我的关系是:

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;

怎么了?

4

1 回答 1

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'))
于 2013-02-11T02:59:05.680 回答