post - YII 2,方法不允许 (#405)

标签 post get yii2 http-status-code-405

  • 当我在 GridView 中删除一条记录时,我的主机上出现了这个错误 服务器。
  • 本地运行没有问题。

我不明白的是:

The error says -> Method Not Allowed. This url can only handle the following request methods: POST.

当我查看我的代码时:

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

它的帖子?!

当我更改为 GET 时,它可以正常工作,但也没有删除确认提示....

我要提问:

  • 为什么我收到一条消息 -> 只允许发布,当它是 Post 时?
  • 当我更改为 GET 时,如何获得删除确认

抱歉我的英语不好,非常感谢您的帮助。

enter image description here

最佳答案

您可能在 Controller behaviors 方法中设置了一个 VerbFilter,它阻止调用 delete 操作以使用 GET 方法。

类似的东西:

public function behaviors()
{
    return [
        'verbs' => [
            'class' => \yii\filters\VerbFilter::className(),
            'actions' => [
                'index'  => ['GET'],
                'view'   => ['GET'],
                'create' => ['GET', 'POST'],
                'update' => ['GET', 'PUT', 'POST'],
                'delete' => ['POST', 'DELETE'],
            ],
        ],
    ];
}

您可以阅读有关 VerFilter 的更多信息 here

你必须选择:

  1. behaviors 方法中删除 VerbFilter
  2. 您可以将 data-method="post" 属性添加到您的链接,这将触发 POST 请求而不是 GET

关于post - YII 2,方法不允许 (#405),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43760516/

相关文章:

javascript - Node JS POST 请求返回未定义的正文

Python POST 请求,无需重新加载页面

android - 如何从 Instagram 获取所有故事

angularjs - POST 请求 - Firebase - 预检响应无效(重定向) - CORS

javascript - 如何使用 React 在客户端向外部站点发出 AJAX GET 请求

php - 在yii2框架中使用动态模型时如何设置属性标签?

web-services - 将参数传递给 Web 服务器的两种方法之间的区别?

javascript - Ajax 请求 - 仅获取/加载 Div Id

php - Yii2 : Search in Gridview using Pjax POST Method with pagination

activerecord - ActiveRecord通过表的位置和顺序