2016-07-04 10 views
1

私のコントローラにGET要求のみを許可したいと思い、VerbFilterを添付しました。ドキュメントでは、要求のメソッドが許可されていないときに405 httpステータスコードを返さなければならないと言いますが、代わりに500ステータスコードがあります。あなたが見ることができるようにYii2 VerbFilterは405の代わりに500のステータスコードを返します

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 

は、&過去のエラーは、現在のエラーの複製です。私はそれの理由についてのアイデアはありません。

+0

500 405エラーを受け取ることになりますですサーバーエラー、私はあなたがエラーがあると思います。 GETによるリクエストは正常に機能しますか? –

+0

@Jørgenはい、GETは正常に動作します。エラーメッセージは、別のエラーを処理中にエラーを通知します。つまり、VerbFilterは2つのエラーを出します。私はVerbFilterを2回付けました。しかし、私はしません。 Wtf ... :( –

+0

は500エラーのログを提供します –

答えて

1

最初のエラー: "Previous Error" - エラーハンドラのリダイレクトでは405です。 2番目のエラーは:あなたのエラー・アクションは、「GET」リクエストも望んでいるが、要求の同じタイプを得たように見えます=>無限ループ

は、あなたの動詞フィルターのためのアクションを指定して、あなたは

public function behaviors(){ 
    return [ 
     'verb' => [ 
     'class' => VerbFilter::className(), 
     'actions' => [ 'action-name' => ['get'] ] 
    ]; 
    } 
+0

はい、動作します。他のアクションとそれが動作します。ありがとう! –

関連する問題