dongtu0088 2017-11-09 17:24
浏览 87
已采纳

100%本地工作的Yii2站点在生产服务器上引发错误

My Yii2 site worked perfectly on my local machine, however since I've uploaded it to the production server I'm getting some odd issues.

The problem is that, while I can add a record using the system, I can't delete or even view the record once it's created. The error is 403 "You are not allowed to perform this action."

I was using the below 'access' rules in my SiteController but I still have the issue even when this section is commented out.

'access' => [
   'class' => AccessControl::className(),
   'only' => ['logout', 'signup', 'create', 'edit', 'index'],
   'rules' => [
           [
           'actions' => ['show'],
           'allow' => true,
                   'roles' => ['?'],
                ],
                [
                        'actions' => ['index', 'logout', 'create', 'edit'],
                        'allow' => true,
                        'roles' => ['@'],
                ],
        ],
],

Edit: two comments around Windows/Linux case sensitivity. The first issue (which I've now deleted from my question) was caused by exactly this.

However the second issue around 403 forbidden issues is still persisting.

I can see the main "index" of each view fine, but trying to "view", "update" or "delete" is not working. As I said, "add" works, but then when it takes me to the "view" action after adding, I get the 403.

The full text of the error, as I'm now ALSO getting the same problem on my local server, is as follows:

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}

Is there anything I should have done to put my site online? Like switch to "production" mode or something? Because I took the files from my local machine, uploaded them as-is to the server, exported and restored the MySQL database and updated the database connection details, but that's all I did.

  • 写回答

1条回答 默认 最新

  • doutan5724 2017-11-09 18:17
    关注

    use this

    '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' => ['@'],
           ],
      ],
    ],
    

    you need to specify the rule for those 'view','update','delete' otherwise you will not be able to access.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 web课程,怎么做啊😭没好好听课 根本不知道怎么下手
  • ¥200 招个渗透测试兼职!需技术大拿!
  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释
  • ¥40 matlab简单代码修改补充
  • ¥15 python提取.csv文件中的链接会经常出现爬取失败
  • ¥15 数据结构中的数组地址问题
  • ¥15 maya的mel里,怎样先选择模型A,然后利用mel脚本自动选择有相同名字的模型B呢。
  • ¥15 Python题,根本不会啊
  • ¥15 会会信号与系统和python的来
  • ¥15 关于#python#的问题