[英]Assigning roles to a user in registration process [yii (users + auth)]
Im using users + auth modules in Yii. 我在Yii中使用用户+身份验证模块。 I've made 3 roles in auth using administration:
我已经使用管理在auth中做了3个角色:
auth/role/
Also, in users module 另外,在用户模块中
user/profileField
I've made one profile field which will determinate in registration page, what account you want to make 我已经创建了一个个人资料字段,该字段将在注册页面中确定,您要创建哪个帐户
[boolean: true="Company" false="Other"]
Admin acc can be only created in module 管理员帐户只能在模块中创建
I want to assign roles based on this field in registration process. 我想在注册过程中基于此字段分配角色。 I assume i should write this in this method (?):
我想我应该用这种方法写这个(?):
/user/controllers/RegistrationController.php:
public function actionRegistration(){...
...
if ($model->save()) {
$profile->user_id=$model->id;
....my role assign here ?...
$profile->save();
...
btw: is it classy to change /user/controllers/RegistrationController.php directly ? 顺便说一句:直接更改/user/controllers/RegistrationController.php是否优雅?
To assign roles to users use: 要将角色分配给用户,请使用:
Yii::app()->authManager->assign($role,$userId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.