FOSUserBundle, symfony 2.1. How can I add a role to a user at registration?

删除回忆录丶 提交于 2020-01-01 19:16:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!