FOSUserBundle, symfony 2.1. 如何在注册时给用户增加一个角色?[英] FOSUserBundle, symfony 2.1. How can I add a role to a user at registration?

本文是小编为大家收集整理的关于FOSUserBundle, symfony 2.1. 如何在注册时给用户增加一个角色?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我确定这是一个简单的问题,但我看不到或找到正确的方法.

使用注册表格创建该用户时,如何向用户添加角色?

推荐答案

找到了它.我在正确的轨道上:)

覆盖注册表格处理程序.

blob/master/resources/doc/overriding_forms.md

添加

$user->addRole('ROLE_MYROLE');

之前
parent::onSuccess()

本文地址:https://www.itbaoku.cn/post/2090782.html

问题描述

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?

推荐答案

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()