Bonjour,

Je n'arrive pas à procéder à l'enrigistrement d'un utilisateur après avois mis 3 relations bidirectionnelles sur la surchage de l'entité Users, sans ces surcharges, tout se déroule parfaitement.

Je vous mets tout d'abord l'erreur Symfony2 :

Catchable Fatal Error: Argument 1 passed to UserBundle\Entity\Users::addContact() must be an instance of UserBundle\Entity\Contacts, string given, called in C:\wamp2\www\ecommerce\vendor\symfony\symfony\src\Symfony\Component\PropertyAccess\PropertyAccessor.php on line 486 and defined

Voilà mon entité Users après surcharge :

<?php

namespace UserBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * Users
 *
 * @ORM\Table("sy_users")
 * @ORM\Entity
 */
class Users extends BaseUser
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construt()
    {
        parent::__construct();
        $this->contact = new \Doctrine\Common\Collections\ArrayCollection();
        $this->address = new \Doctrine\Common\Collections\ArrayCollection();
        $this->professional = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * @ORM\OneToMany(targetEntity="UserBundle\Entity\Contacts", mappedBy="user", cascade={"remove"})
     * @ORM\JoinColumn(nullable=true)
     */
    private $contact;

    /**
     * @ORM\OneToMany(targetEntity="UserBundle\Entity\Address", mappedBy="user", cascade={"remove"})
     * @ORM\JoinColumn(nullable=true)
     */
    private $address;

    /**
     * @ORM\OneToMany(targetEntity="UserBundle\Entity\Professionals", mappedBy="user", cascade={"remove"})
     * @ORM\JoinColumn(nullable=true)
     */
    private $professional;

    /**
     * @var string
     *
     * @ORM\Column(name="typeCustomer", type="string", length=5)
     */
    private $typeCustomer;

    /**
     * @var string
     *
     * @ORM\Column(name="numCustomer", type="string", length=15)
     */
    private $numCustomer;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set typeCustomer
     *
     * @param string $typeCustomer
     *
     * @return Users
     */
    public function setTypeCustomer($typeCustomer)
    {
        $this->typeCustomer = $typeCustomer;

        return $this;
    }

    /**
     * Get typeCustomer
     *
     * @return string
     */
    public function getTypeCustomer()
    {
        return $this->typeCustomer;
    }

    /**
     * Set numCustomer
     *
     * @param string $numCustomer
     *
     * @return Users
     */
    public function setNumCustomer($numCustomer)
    {
        $this->numCustomer = $numCustomer;

        return $this;
    }

    /**
     * Get numCustomer
     *
     * @return string
     */
    public function getNumCustomer()
    {
        return $this->numCustomer;
    }

    /**
     * Add contact
     *
     * @param \UserBundle\Entity\Contacts $contact
     *
     * @return Users
     */
    public function addContact(\UserBundle\Entity\Contacts $contact)
    {
        $this->contact[] = $contact;

        return $this;
    }

    /**
     * Remove contact
     *
     * @param \UserBundle\Entity\Contacts $contact
     */
    public function removeContact(\UserBundle\Entity\Contacts $contact)
    {
        $this->contact->removeElement($contact);
    }

    /**
     * Get contact
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getContact()
    {
        return $this->contact;
    }

    /**
     * Add address
     *
     * @param \UserBundle\Entity\Address $address
     *
     * @return Users
     */
    public function addAddress(\UserBundle\Entity\Address $address)
    {
        $this->address[] = $address;

        return $this;
    }

    /**
     * Remove address
     *
     * @param \UserBundle\Entity\Address $address
     */
    public function removeAddress(\UserBundle\Entity\Address $address)
    {
        $this->address->removeElement($address);
    }

    /**
     * Get address
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAddress()
    {
        return $this->address;
    }

    /**
     * Add professional
     *
     * @param \UserBundle\Entity\Professionals $professional
     *
     * @return Users
     */
    public function addProfessional(\UserBundle\Entity\Professionals $professional)
    {
        $this->professional[] = $professional;

        return $this;
    }

    /**
     * Remove professional
     *
     * @param \UserBundle\Entity\Professionals $professional
     */
    public function removeProfessional(\UserBundle\Entity\Professionals $professional)
    {
        $this->professional->removeElement($professional);
    }

    /**
     * Get professional
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getProfessional()
    {
        return $this->professional;
    }
}

Voilà ce que me renvoie mon formulaire d'enregistrement après validation :

array (size=1)
  'fos_user_registration_form' => 
    array (size=12)
      'email' => string 'test@test.test' (length=14)
      'username' => string 'test' (length=4)
      'plainPassword' => 
        array (size=2)
          'first' => string 'azertyui' (length=8)
          'second' => string 'azertyui' (length=8)
      'typeCustomer' => string 'pro' (length=3)
      'numCustomer' => string '41005066' (length=8)
      'enabled' => string '0' (length=1)
      'locked' => string '1' (length=1)
      'contact' => 
        array (size=6)
          'lastname' => string 'test' (length=4)
          'firstname' => string 'test' (length=4)
          'phone' => string 'test phone' (length=10)
          'mail' => string 'test@test.test' (length=14)
          'fax' => string '' (length=0)
          'cellphone' => string '' (length=0)
      'address' => 
        array (size=5)
          'street' => string 'La Gotta 11' (length=11)
          'complement' => string '' (length=0)
          'town' => string 'PARIS' (length=5)
          'postal' => string '75010' (length=5)
          'country' => string 'FR' (length=2)
      'professional' => 
        array (size=5)
          'business' => string 'TEST SARL' (length=9)
          'siret' => string '' (length=0)
          'icVat' => string '' (length=0)
          'delay' => string '0' (length=1)
          'vat' => string '1' (length=1)
      'create' => string '' (length=0)
      '_token' => string 'ZrTaxNqhzcpqf6zb2ARJ_jVMjun7zpKvvEwgqQqw40c' (length=43)

Je vous mets la surcharge du formulaire d'inscription, si l'erreur viens de là :

<?php

namespace UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('typeCustomer', 'choice', array('label'    => 'registration.typeCustomer', 'translation_domain' => 'FOSUserBundle',
                                                      'choices'  => array('part' => 'form.part',
                                                                          'pro' => 'form.pro',
                                                                          'admin' => 'form.admin',
                                                                          'assoc' => 'form.assoc'),
                                                      'preferred_choices' => array('part')))
                ->add('numCustomer', 'hidden', array('data' => '1510-10-00001'))
                ->add('enabled', 'hidden', array('data' => 1))
                ->add('locked', 'hidden', array('data' => 0))
                ->add('contact', new ContactType())
                ->add('address', new AddressType())
                ->add('professional', new ProfessionalType())
                ->add('create', 'submit', array('label' => 'form.create', 'translation_domain' => 'FOSUserBundle'));
    }

    public function getParent()
    {
        return 'fos_user_registration';
    }

    public function getName()
    {
        return 'userbundle_registration';
    }
}

J'ai essayé de passé 'contact' , 'address' et 'professional' en collection, mais je n'y arrive pas, cela viendrait-il de là ?
Alors j'ai essayé de creuser, mais tout ce que j'ai essayé c'est soldé par un échec.

Merci d'avance pour votre aide.

Aucune réponse