How To Turn Of Filters For 404 Pages?

Hi,

I have an “age gate” filter in my Controller (all controllers extend from it). It simply checks if a user has a “I’m old enough” cookie and - if he doesn’t - redirects him to a “what’s you birthday” page. It works all right with one exception - nonexistent files. For example, if I don’t have a robots.txt file and it’s requested, the filter kicks in (and I don’t want it to be).

The solution would be to skip running this filter for 404 pages or check if it’s 404 within the filter and return true if that’s the case. How to I accomplish either of them?

kind regards,

Matt

Hi Matt,

What about using a dedicated controller that doesn’t inherit your Controller for error pages?




// config/main.php

'components' => array(

    ...

    'errorHandler'=>array(

        // use 'site/error' action to display errors

        // 'errorAction'=>'site/error',

        'errorAction'=>'noAgeGate/error',

    ),

    ...



In the above NoAgeGateController extends directly from CController.

Or, I guess you can reset the errorAction property of errorHandler to null.




// config/main.php

'components' => array(

    ...

    'errorHandler'=>array(

        // use 'site/error' action to display errors

        // 'errorAction'=>'site/error',

    ),

    ...



It will display the standard error pages of Yii.

http://www.yiiframework.com/doc/api/1.1/CErrorHandler#errorAction-detail

Thank you. I ended up modifying .htaccess to not route anything “with an extension” through the app. By default, if for example robots.txt doesn’t exist, the app attemts (unsuccessfully) to route it to a controller/action and displays 404.