douqiangchuai7674 2016-06-29 04:28
浏览 125
已采纳

yii2删除记录错误

i getting error while deleting record in all table:

An Error occurred while handling another error:
exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to perform this action.' in D:\FORBIDDEN\projects\UniServerZ\www\project\vendor\yiisoft\yii2\filters\AccessControl.php:151
Stack trace:

Previous exception:
exception 'yii\web\MethodNotAllowedHttpException' with message 'Method Not Allowed. This url can only handle the following request methods: POST.' in D:\FORBIDDEN\projects\UniServerZ\www\project\vendor\yiisoft\yii2\filters\VerbFilter.php:105
Stack trace:

_

here my controller:

public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }


public function actionDelete($id)
{
   $this->findModel($id)->delete();
   return $this->redirect(['index']);
}

and my delete button in view.php

<?= Html::a('Delete', ['delete', 'id' => $model->id_transaksi], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
        ]) 
?>


its working when i replaced POST with GET, but alert confirm not working.. do you know what's wrong? help, please

  • 写回答

2条回答 默认 最新

  • dongyuan2652 2016-06-30 08:33
    关注

    It might be that you get the error message

    Method Not Allowed. This url can only handle the following request methods: POST.
    

    because somehow the browser reloads the page with requested url. When you click on the link to delete that model, the request method is POST, as it is specified. At that point some exception occurs (seems to be related to access rules) that makes you browser forgive about the request method.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog