I am wondering here… how can one create an application-wide filter in Yii?
Since the default CController->filter() gets overridden, then the only decent way I could think of, was implementing the filter method of the top-level controller and then calling parent::filters() in every individual controller along with array_merge.
Is there a better way to do something like this? I simply need to invoke some site-specific code before any action executes but the controller must already be resolved, created and accessible, so the ‘onBeginRequest’ event does not seem to suit the occasion.
Why not just derive all of your controllers from a subclass of CController? I do that as a standard in all my apps.
You then implement what you need where you need it.
I already do derive my controllers from a subclass of CController. It’s the default option when using the yiic tool.
However, I’d rather not write my own implementation of CController->run() because if the official Yii framework changes in that respect, I’d be stuck. Yii has a good core feature to counter situations like that - events. They allow altering the functionality of a component without changing it’s code. Unfortunately the default implementation of CController raises exactly 0 events and right now I see no forward-compatible way to improve the behavior of CController on my own.