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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵