标签:yii2 rbac
web.php的配置
‘authManager‘ => [
‘class‘ => ‘yii\rbac\DbManager‘,
‘itemTable‘ => ‘chat_auth_item‘,
‘assignmentTable‘ => ‘chat_auth_assignment‘,
‘itemChildTable‘ => ‘chat_auth_item_child‘,
],
2. Controller.php里需要添加
public function beforeAction($action)
{
if(!parent::beforeAction($action)){
return false;
}
$controllerId = \Yii::$app->controller->id;
$actionId = \Yii::$app->controller->action->id;
$action = $controllerId.‘/‘.$actionId;
if(\Yii::$app->user->can($action)){
return true;
}else{
$json = ‘{"error":"noright"}‘;
echo $json;
return false;
}
}
说明:用controllerId/actionId代表某个具体的操作。比如UserController.php里的注册actRonregister,则具体的权限为: user/register。
本文出自 “编程艺术” 博客,请务必保留此出处http://itsart.blog.51cto.com/1005243/1836993
标签:yii2 rbac
原文地址:http://itsart.blog.51cto.com/1005243/1836993