Yii2 VerbFilter returns 500 状态码而不是 405

Yii2 VerbFilter returns 500 status code instead of 405

我只想允许对我的控制器发出 GET 请求,并且我附加了 VerbFilter。文档说当不允许请求的方法时它必须 return 405 http 状态代码,但我得到的是 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

如您所见,之前的错误与当前错误重复。我不知道这是什么原因。

第一个错误:“Previous Error”- 是 405,在错误处理程序上重定向。 第二个错误:您的错误操作也需要 'GET' 请求,但看起来得到了相同类型的请求。=> 无限循环

为动词过滤器指定操作,您将收到 405 错误

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