FOS surcharger le Form register
J'ai cherché, j'ai trouvé une tripotée de fois la même question mais jamais la réponse :
Je veux rajouter une checkbox lors de l’inscription j'ai donc fait :
\Symfony\app\config\config.yml
Code:
1 2 3 4 5 6 7 8
| #securite
fos_user:
db_driver: orm # Le type de BDD ÃÂ* utiliser, nous utilisons l'ORM Doctrine depuis le début
firewall_name: main # Le nom du firewall duquel on utilisera ces utilisateurs
user_class: PV\UserBundle\Entity\User #
registration:
form:
type: pv_user_registration |
\Symfony\src\PV\UserBundle\Entity\User.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <?php
// src/PV/UserBundle/Entity/User.php
namespace PV\UserBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="pv_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="PV\GroupeBundle\Entity\Groupe")
* @ORM\JoinColumn(nullable=true)
*/
protected $mongroupe;
/**
* @var boolean
*
* @ORM\Column(name="notifmail", type="boolean")
*/
private $notifmail;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set mongroupe
*
* @param \PV\GroupeBundle\Entity\Groupe $mongroupe
* @return User
*/
public function setMongroupe(\PV\GroupeBundle\Entity\Groupe $mongroupe = null)
{
$this->mongroupe = $mongroupe;
return $this;
}
/**
* Get mongroupe
*
* @return \PV\GroupeBundle\Entity\Groupe
*/
public function getMongroupe()
{
return $this->mongroupe;
}
/**
* Set notifmail
*
* @param boolean $notifmail
* @return User
*/
public function setNotifmail($notifmail)
{
$this->notifmail = $notifmail;
return $this;
}
/**
* Get notifmail
*
* @return boolean
*/
public function getNotifmail()
{
return $this->notifmail;
}
} |
\Symfony\src\PV\UserBundle\Form\Type\RegistrationFormType.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?php
namespace PV\UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilder $builder, array $options)
{
parent::buildForm($builder, $options);
// Ajoutez vos champs ici, revoilà notre champ *location* :
$builder->add('notifmail');
}
public function getName()
{
return 'pv_user_registration';
}
} |
et :
\Symfony\src\PV\UserBundle\Resources\config\services.yml
Code:
1 2 3 4 5 6 7
| # src/PV/UserBundle/Resources/config/services.yml
services:
pv_user.registration.form.type:
class: PV\UserBundle\Form\Type\RegistrationFormType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: pv_user_registration } |
Et j'ai cette foutu erreur :
Citation:
Could not load type "pv_user_registration"
in C:\perso\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php at line 95