- 当我在 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 时,如何获得删除确认
抱歉我的英语不好,非常感谢您的帮助。
最佳答案
您可能在 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
你必须选择:
- 从
behaviors
方法中删除 VerbFilter - 您可以将
data-method="post"
属性添加到您的链接,这将触发POST
请求而不是GET
。
关于post - YII 2,方法不允许 (#405),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43760516/