gpt4 book ai didi

yii2 - Forbidden (#403) - 您不能执​​行此操作?

转载 作者:行者123 更新时间:2023-12-02 17:31:02 26 4
gpt4 key购买 nike

这是后端 SiteController.php 访问规则。当我浏览此 url site.com/backend/web/site/login 时。它显示禁止 (#403)。

return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index', 'addhotels'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];

最佳答案

An Error occurred while handling another error: exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to perform this action.' in C:\wamp\www\k\kometonline\vendor\yiisoft\yii2\filters\AccessControl.php:151

我也遇到了这个错误,通过 Google 找到了这个页面,希望这对其他人有帮助。

错误发生是因为您添加了访问控制,但您还需要在站点 Controller 中明确允许“错误”操作,否则您将得到相同的错误。它不是很明显,因为没有针对它的操作,还要添加“验证码”操作,否则你会遇到同样的问题。

在您的站点 Controller 中:

public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['register','login'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
[
//see captcha and error added here, this fixes the issue
'actions' => ['contact', 'about', 'terms', 'forgot', 'reset-password', 'captcha', 'error'],
'allow' => true,
'roles' => ['?', '@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}

关于yii2 - Forbidden (#403) - 您不能执​​行此操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33345814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com