问题
I'm sure this is a simple question but I can't quite see or find the correct way to do it.
How do I add a role to a user when that user is created using the registration form?
回答1:
Found it. I was on the right track :)
Override the registration form handler.
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md
Add
$user->addRole('ROLE_MYROLE');
before
parent::onSuccess()
来源:https://stackoverflow.com/questions/12398754/fosuserbundle-symfony-2-1-how-can-i-add-a-role-to-a-user-at-registration