I followed the documentation to redefine the registration form of FosUser, and I show the roles that I want, like this. Here is my registration form.
<?php namespace My\BlogBundle\Form; use My\BlogBundle\Entity\User; use Symfony\Component\Form\FormBuilder; use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType; class MyRegisterType extends BaseType { public function buildForm(FormBuilder $builder, array $options) { parent::buildForm($builder ,$options); $user = new User(); $builder ->add('roles' ,'choice' ,array('choices'=>$user->getRoles() ) ; } public function getName() { return 'my_register_type'; } }
And here is my user identity.
<?php namespace My\BlogBundle\Entity; use FOS\UserBundle\Entity\User as BaseUser; use Doctrine\ORM\Mapping as ORM; class User extends BaseUser { protected $id; protected $roles=array(); protected $article; protected $comment; public function __construct() { parent::__construct(); $this->roles=array('searcher' ,'annoucer'); } }
My problem now is that I donβt know how to display in this field only the roles that I added, because I get ROLE_USER with selections and when I submit the form I get this error
Catchable Fatal Error: Argument 1 passed to FOS \ UserBundle \ Model \ User :: setRoles () must be an array, string given, called in / var / www / blog / vendor / symfony / src / Symfony / Component / Form / Util /PropertyPath.php on line 346 and defined in /var/www/blog/vendor/bundles/FOS/UserBundle/Model/User.php line 709
Any help would be more than appreciated, thanks. BTW Sorry, I could not add other tags: P
source share