Filters in Yii framework

| Last Updated: | 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

HttpCache

This is used for client-side caching.


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:


, , ,