O'Reilly logo

Mastering Yii by Charles R. Portwood II

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Verb filters

When creating custom API endpoints, you may want to only allow certain HTTP verbs to be issued against these actions. For instance, a PUT request to an endpoint that deletes a user doesn't make much sense. One way to control which HTTP verbs can be executed against our actions is to use yii\filters\VerbFilter. When using yii\filters\VerbFilter, we simply need to specify which HTTP verbs will be accepted by each of our public actions. The following example shows the default verb filter that is used by yii\rest\ActiveController:

public function behaviors() { return [ 'verbs' => [ 'class' => \yii\filters\VerbFilter::className(), 'actions' => [ 'index' => ['get'], 'view' => ['get'], 'create' => ['get', 'post'], 'update' => ['get', 'put', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required