方法不允许(#405) [英] Method not allowed(#405)
本文介绍了方法不允许(#405)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码抛出这样的错误:"不允许的方法 (#405)方法不允许.这个url只能处理以下请求方法:."
following code throws out error like this: "Method Not Allowed (#405) Method Not Allowed. This url can only handle the following request methods: ."
任何想法,如何解决这个问题?
Any ideas,how to fix this?
['label' => 'Logout', 'url' => ['/site/logout'], 'linkOptions' => ['data' => ['method' => 'post']]],
这里仍然是 SiteController 中的方法:
Here is still method in SiteController:
public function actionLogout() {
Yii::$app->user->logout();
return $this->goHome();
}
推荐答案
use data-method in linkOptions
use data-method in linkOptions
['label' => 'logOut',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
],
注意:检查站点控制器中的行为
notice:check behavior in sitecontroller
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'dashboard'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
这篇关于方法不允许(#405)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文