- 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。
时间: 2024-10-09 20:44:18