100% 本地工作的 Yii2 站点在生产服务器上抛出错误
100% locally-working Yii2 site throws errors on production server
我的 Yii2 站点在我的本地机器上运行完美,但是自从我将它上传到生产服务器后,我遇到了一些奇怪的问题。
问题是,虽然我可以使用系统添加记录,但创建后我无法删除甚至查看记录。错误是 403 "You are not allowed to perform this action."
我在我的 SiteController 中使用了以下 'access' 规则,但即使此部分已被注释掉,我仍然遇到问题。
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'create', 'edit', 'index'],
'rules' => [
[
'actions' => ['show'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['index', 'logout', 'create', 'edit'],
'allow' => true,
'roles' => ['@'],
],
],
],
编辑:关于 Windows/Linux 区分大小写的两条评论。第一个问题(我现在已经从我的问题中删除了)正是由此引起的。
但是围绕403禁止问题的第二个问题仍然存在。
我可以很好地看到每个视图的主要 "index",但尝试 "view"、"update" 或 "delete" 无效。正如我所说,"add" 有效,但是当它在添加后将我带到 "view" 操作时,我得到 403.
错误的全文如下:
exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to perform this action.' in D:\Websites\cabana\advanced\vendor\yiisoft\yii2\filters\AccessControl.php:154
Stack trace:
#0 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\filters\AccessControl.php(137): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
#1 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\ActionFilter.php(75): yii\filters\AccessControl->beforeAction(Object(yii\base\InlineAction))
#2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
#3 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Component.php(545): call_user_func(Array, Object(yii\base\ActionEvent))
#4 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Controller.php(272): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#5 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\web\Controller.php(164): yii\base\Controller->beforeAction(Object(yii\base\InlineAction))
#6 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Controller.php(154): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
#7 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Module.php(523): yii\base\Controller->runAction('view', Array)
#8 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\web\Application.php(102): yii\base\Module->runAction('job/view', Array)
#9 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
#10 D:\Websites\cabana\advanced\backend\web\index.php(18): yii\base\Application->run()
#11 {main}
我应该做些什么才能让我的网站上线?比如切换到 "production" 模式之类的?因为我从我的本地机器上获取了文件,将它们原样上传到服务器,导出并恢复了 MySQL 数据库并更新了数据库连接详细信息,但仅此而已。
使用这个
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'create', 'edit','index','view','update','delete'],
'rules' => [
[
'actions' => ['show'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['index', 'logout', 'create', 'edit','view','update','delete'],
'allow' => true,
'roles' => ['@'],
],
],
],
需要为'view','update','delete'指定规则,否则将无法访问。
我的 Yii2 站点在我的本地机器上运行完美,但是自从我将它上传到生产服务器后,我遇到了一些奇怪的问题。
问题是,虽然我可以使用系统添加记录,但创建后我无法删除甚至查看记录。错误是 403 "You are not allowed to perform this action."
我在我的 SiteController 中使用了以下 'access' 规则,但即使此部分已被注释掉,我仍然遇到问题。
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'create', 'edit', 'index'],
'rules' => [
[
'actions' => ['show'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['index', 'logout', 'create', 'edit'],
'allow' => true,
'roles' => ['@'],
],
],
],
编辑:关于 Windows/Linux 区分大小写的两条评论。第一个问题(我现在已经从我的问题中删除了)正是由此引起的。
但是围绕403禁止问题的第二个问题仍然存在。
我可以很好地看到每个视图的主要 "index",但尝试 "view"、"update" 或 "delete" 无效。正如我所说,"add" 有效,但是当它在添加后将我带到 "view" 操作时,我得到 403.
错误的全文如下:
exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to perform this action.' in D:\Websites\cabana\advanced\vendor\yiisoft\yii2\filters\AccessControl.php:154
Stack trace:
#0 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\filters\AccessControl.php(137): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
#1 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\ActionFilter.php(75): yii\filters\AccessControl->beforeAction(Object(yii\base\InlineAction))
#2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
#3 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Component.php(545): call_user_func(Array, Object(yii\base\ActionEvent))
#4 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Controller.php(272): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#5 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\web\Controller.php(164): yii\base\Controller->beforeAction(Object(yii\base\InlineAction))
#6 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Controller.php(154): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
#7 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Module.php(523): yii\base\Controller->runAction('view', Array)
#8 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\web\Application.php(102): yii\base\Module->runAction('job/view', Array)
#9 D:\Websites\cabana\advanced\vendor\yiisoft\yii2\base\Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
#10 D:\Websites\cabana\advanced\backend\web\index.php(18): yii\base\Application->run()
#11 {main}
我应该做些什么才能让我的网站上线?比如切换到 "production" 模式之类的?因为我从我的本地机器上获取了文件,将它们原样上传到服务器,导出并恢复了 MySQL 数据库并更新了数据库连接详细信息,但仅此而已。
使用这个
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'create', 'edit','index','view','update','delete'],
'rules' => [
[
'actions' => ['show'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['index', 'logout', 'create', 'edit','view','update','delete'],
'allow' => true,
'roles' => ['@'],
],
],
],
需要为'view','update','delete'指定规则,否则将无法访问。