Filters in Yii framework

Filters are objects that run before and/or after controller actions.A filter may consist of a pre-filter (filtering logic applied before actions) and/or a post-filter (logic applied after actions). You give it a php function name to run, and it will run that function on the value of the attribute, when validate() is called.

How to Use Filters

When multiple filters are configured for a single action, they are applied according to the rules described below:

Creating Filters in yii framework

To create a new action filter, extend from yii\base\ActionFilter and override the beforeAction() and/or afterAction() methods.

The following example shows a filter that logs the action execution time:

Authentication Method Filters


This is used for client-side caching.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article Tags: , , ,