I have created a standard yii\rest\ActiveController and added my custom action to it:
public function actionTest($id)
{
return ['test' => $id];
}
I have added a new entry to extraPatterns of rules of yii\web\UrlManager:
'extraPatterns' => [
'GET test/{id}' => 'test',
],
Following this answer, I have also added new verb definition in my REST controller:
public function verbs()
{
$verbs = parent::verbs();
$verbs['test'] = ['GET'];
return $verbs;
}
But it turned out to be not needed. Meaning that I can comment out the above piece of code (the entire method in this case) and the whole new REST route is still working:
What am I missing? Why I don't need to specify this new action / router in verbs() for GET (I figured out that I must do this for other verbs)?


In the referenced question/answer you were working with existing action
indexthat already had rule foryii\filters\VerbFilterto only allowGETorHEADverbs for that action.But in case of completely new action
testthere is no existing rule forVerbFilter. If there is no rule for action theVerbFilterwill allow any request. That's why if you don't specify rule fortestaction any verb set up in router will work. Once you specify the rule fortestinverbs()method, only allowed verbs will make it throughVerbFilter.