1
我想只允許GET請求到我的控制器,並且我附加了VerbFilter。該文檔說,當請求的方法不被允許時,它必須返回405 http狀態碼,但是我得到了500個狀態碼。Yii2 VerbFilter返回500狀態代碼而不是405
class MyController extends Controller {
...
public function behaviors(){
return [
'verb' => [
'class' => VerbFilter::className(),
'actions' => [ '*' => ['get'] ]
];
}
public function actions(){
return [ 'error' => [
'class' => 'yii\web\ErrorAction'
]];
}
...
}
錯誤消息
An Error occurred while handling another error:
exception 'yii\web\MethodNotAllowedHttpException' with message
'Method Not Allowed. This url can only handle the following request methods: GET.'
in /yii_project/vendor/yiisoft/yii2/filters/VerbFilter.php:105
Previous exception:
exception 'yii\web\MethodNotAllowedHttpException' with message
'Method Not Allowed. This url can only handle the following request methods: GET.'
in /yii_project/vendor/yiisoft/yii2/filters/VerbFilter.php:105
正如你所看到的,previos錯誤是當前錯誤的重複。我對它的一個原因沒有想法。
500服務器錯誤,所以我想你有錯誤。請求使用GET工作是否成功? –
@Jørgen是的,GET工作成功。錯誤消息在處理另一個錯誤時告訴錯誤。所以,VerbFilter會給出兩個錯誤。就像我附加了兩次VerbFilter。但我不知道。 Wtf ... :( –
提供日誌爲500錯誤 –