繁体   English   中英

在注册过程中为用户分配角色[yii(用户+身份验证)]

[英]Assigning roles to a user in registration process [yii (users + auth)]

我在Yii中使用用户+身份验证模块。 我已经使用管理在auth中做了3个角色:

auth/role/ 
  1. 管理员
  2. 公司
  3. 其他

另外,在用户模块中

user/profileField

我已经创建了一个个人资料字段,该字段将在注册页面中确定,您要创建哪个帐户

[boolean: true="Company" false="Other"]

管理员帐户只能在模块中创建

我想在注册过程中基于此字段分配角色。 我想我应该用这种方法写这个(?):

/user/controllers/RegistrationController.php:
public function actionRegistration(){...
...
 if ($model->save()) {
                        $profile->user_id=$model->id;
                        ....my role assign here ?...
                        $profile->save();
 ...

顺便说一句:直接更改/user/controllers/RegistrationController.php是否优雅?

要将角色分配给用户,请使用:

Yii::app()->authManager->assign($role,$userId);

如这里解释

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM