Filters in Yii framework

Prem Tiwari - - 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.

Prem Tiwari

Prem Tiwari is the founder of and also a professional developer and a blogger by hobby.

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.