Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii controller filters() method pattern

Tags:

filter

yii

every controller should have method filters(), there you can specify some classes, i want to know, how those classes are include by framework ? how those classes are configuring, and when, and maybe someone can give me a pattern for this way of using filters() and including some classes ?

like image 389
RusAlex Avatar asked Nov 23 '25 12:11

RusAlex


1 Answers

The controller filters are classes deriving from CFilter.

As the documentation example shows, you configure them inside your controller like this:

public function filters()
    {
        return array(
            'postOnly + edit, create',
            array(
                'application.filters.PerformanceFilter - edit, create',  // 1
                'unit'=>'second',                                        // 2
                'amount'=>42,                                            // 3
            ),
        );
    }

In the line marked 1 you provide the path for the hypothetical class PerformanceFilter; Yii loads that as any other component.

In the line marked 2 and 3 you initialize properties. You can go on with any number of key/value pairs; they will all get used to set the filter's properties with the corresponding names.

like image 171
Jon Avatar answered Nov 26 '25 17:11

Jon