禁止(#403) - 您不被允许执行此操作[Yii2]

Art*_*a09 4 yii2

我试过map在后端添加菜单.我用yii2-advanced.这是我的"控制器"代码:

public function actionMap()
{
    return $this->render('map');
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用此URL访问它时http://localhost/yii2advanced/backend/web/index.php?r=site/map,我收到了错误消息Forbidden (#403) - You are not allowed to perform this action.我不明白为什么我收到此错误消息,有人可以帮我解决这个问题吗?

aro*_*hev 7

它是由AccessControl引起的.很可能map根据访问规则阻止了操作.允许所有经过身份验证的用户的示例:

/**
 * @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
            ],
        ],
    ];
}
Run Code Online (Sandbox Code Playgroud)

或者,您可以根据某些RBAC角色调整访问权限.