rbac permissions can be verified normally, but when verifying in the controller, an exception is thrown
The code in the controller is like this
public function beforeAction($action) {
<code>$controller = Yii::$app->controller->id; //获取控制器 $action = Yii::$app->controller->action->id; //获取方法 if(Yii::$app->user->can($controller.'_'.$action)){ return true; }else{ throw new \yii\web\UnauthorizedHttpException('你没有操作权限'); }</code>
}
When you get to the page, it will show the prompt that you have no operation permission. The corresponding $controller.'_'.$action data has been added to the database...
rbac permissions can be verified normally, but when verifying in the controller, an exception is thrown
The code in the controller is like this
public function beforeAction($action) {
<code>$controller = Yii::$app->controller->id; //获取控制器 $action = Yii::$app->controller->action->id; //获取方法 if(Yii::$app->user->can($controller.'_'.$action)){ return true; }else{ throw new \yii\web\UnauthorizedHttpException('你没有操作权限'); }</code>
}
When you get to the page, it will show the prompt that you have no operation permission. The corresponding $controller.'_'.$action data has been added to the database...
Write the real address in the data, such as:
'/'.$controller.'/'.$action
Please output $controller.'_'.$action
This variable, I use it myself under the parent class,
Yii::$app->controller->id and Yii::$app-> ;controller->action->id is null