myTD
myTD

Reputation: 1469

Adding Role Using FOSUser Bundle Symfony

I am using and very new to symfony2

using FOSUser Bundle.

/register page provides - UserName, Email, Password, ConfirmPassword..

I want to also set the Role here using the registration form..

so it will be

textbox --> UserName
textbox --> Password
textbox --> email
radioBox --> x Admin x Moderator

how can i achieve this>

Upvotes: 0

Views: 857

Answers (1)

Michał Jabłoński
Michał Jabłoński

Reputation: 38

"roles" field in User class is array (serialized in db), so in your form you can use "choice" form type (http://symfony.com/doc/current/reference/forms/types/choice.html) with options multiple=true/false & expanded=true and during form processing just save form field value to your user object

in "choices" option of your form field, put array with your roles, for example:

$builder->add('roles', 'choice', array(
    'choices' => array('ROLE_USER' => 'Standard User', 'ROLE_ADMIN' => 'Administrator')
));

Upvotes: 2

Related Questions