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

HttpCache

This is used for client-side caching.

Recommended Posts:


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (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: , , ,

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.

Solved Programs