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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据