处理另一个错误时发生错误:
异常 'yii\web\ForbiddenHttpException' 与 C:\wamp\www\k\kometonline\vendor\yiisoft\yii2\web\User.php:431 中的消息“需要登录”
在后端管理员登录页面 (site.com/backend/web/site/login) 中安装 RBAC 后出现此错误。这个问题的主要原因是什么。我不知道要发布什么代码。如果您需要任何代码,请在下面评论。提前致谢。
处理另一个错误时发生错误:
异常 'yii\web\ForbiddenHttpException' 与 C:\wamp\www\k\kometonline\vendor\yiisoft\yii2\web\User.php:431 中的消息“需要登录”
在后端管理员登录页面 (site.com/backend/web/site/login) 中安装 RBAC 后出现此错误。这个问题的主要原因是什么。我不知道要发布什么代码。如果您需要任何代码,请在下面评论。提前致谢。
在遵循本教程时,我在后端管理员登录页面中安装 RBAC 时遇到了同样的错误: RBAC Super Simple with Admin and User
您可以尝试在前端登录时进行更改SiteController,看看是否有效。这两个的区别在于SiteController前端已经在其行为方法中使用了访问规则。
从那里你可以比较SiteController后端和前端的 s,看看是什么使它起作用。就我而言,我只是添加了一行
'only' => ['logout'],
略低于
'class' => AccessControl::className(),
它奏效了!
While I know the solution worked for the OP and is a few years old, I wanted to post how I solved this for myself, in the hope of offering an alternate solution.
In my case, I specified the following actions
'rules' => [
[
'actions' => ['logout', 'index',],
'allow' => true,
'roles' => ['@'],
],
这指定索引和注销受密码保护,
*"'roles' => ['@']"*
说只有经过身份验证的用户才能调用这些操作。
因此,当我的应用程序重新启动时,它会尝试指向登录操作和出现的错误。我通过指定角色为未登录用户(又名客人)指定规则解决了这个问题
*"'roles' => ['?']"*
因此,我的行为方法更改为
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['logout', 'index',],
'allow' => true,
'roles' => ['@'],
],
[
'actions' => ['login'],
'allow' => true,
'roles' => ['?'],
],
],
],
];
}