Home > Blockchain >  OPTION verb is not working for a list of all records in Yii 2 app
OPTION verb is not working for a list of all records in Yii 2 app

Time:06-11

I have enter image description here

What can be wrong or what am I missing?

CodePudding user response:

You are getting 405 Method Not Allowed not because of routing but because of yii\filters\VerbFilter.

The yii\rest\Controller uses verbs() method to set up VerbFilter. The yii\rest\ActiveController overrides verbs() method and sets VerbFilter to only allow GET and HEAD requests for index action. It uses options action for OPTIONS method.

If you really want to use index action for OPTIONS method. You have to override verbs() method yourself and add OPTIONS as allowed method for that action. For example like this:

protected function verbs()
{
    $verbs = parent::verbs();
    $verbs['index'][] = 'OPTIONS';
    return $verbs;
}

Or if you want to use options action you have to modify patterns settings as suggested by @Bizley in comments.

  • Related