Forbidden (#403) - 你不能执行这个动作 [Yii2] [英] Forbidden (#403) - You are not allowed to perform this action [Yii2]
问题描述
我尝试在后端添加菜单 map
.我使用 yii2-advanced
.这是我的控制器"代码:
I've tried to add menu map
in backend-side. I use yii2-advanced
. This is my "controller" code:
public function actionMap()
{
return $this->render('map');
}
但是,当我尝试使用此 url http://localhost/yii2advanced/backend/web/index.php?r=site/map
访问它时,我收到错误消息 Forbidden (#403) - 不允许您执行此操作
.我不明白为什么会收到此错误消息,有人可以帮我解决此问题吗?
But, when I try to access it with this url http://localhost/yii2advanced/backend/web/index.php?r=site/map
, I've got error message Forbidden (#403) - You are not allowed to perform this action
. I don't understand why I got this error message, can anybody help me to fix this problem?
推荐答案
由 访问控制.很可能根据访问规则阻止操作 map
.允许所有经过身份验证的用户使用它的示例:
It's caused by AccessControl. Most likely the action map
is blocked according to access rules. Example of allowing it for all authenticated users:
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => ['create', 'update'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
或者,您可以根据某些 RBAC 角色调整访问权限.
Alternatively you can adjust access according to some RBAC roles.
这篇关于Forbidden (#403) - 你不能执行这个动作 [Yii2]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!