CWebApplication::beforeControllerAction question


In one particular Yii app, CWebApplication has been overridden, using beforeControllerAction() to perform logic before any controller actions are run. I would think that this would apply to actions that have been added to a controller via the actions() method (externally defined CActions), but this does not seem to be the case.

Does anyone know if there is a reason for this?

I will switch to using CWebApplication::onBeforeRequest(), which presumably is a better practice, generally - but I am still curious why an externally-added CAction does not fall under the umbrella of ‘beforeControllerAction’… perhaps there is a good reason for this?



I am noticing a few quirks here that could merit some consideration.

When I apply the onBeginRequest event to my application in main.php, there is a problem. In the event handler code for this event, I am making a call to Yii::app()->user. Now, I have a module which has a different configuration for the ‘user’ component, and so this module has not yet been set up in this onBeginRequest event.

Before, when the logic was in the overridden CWebApplication::beforeControllerAction(), this was not a problem as the module had already been registered and the alternate module-specific user component was registered. But, I had to switch away from this because, for some reason, and as detailed in the previous post, beforeControllerAction does not seem to apply to actions that have been externally defined and added via CController::action().

So, I do appear to be stuck here a bit, as emitting the onBeginRequest event seems to occur too early in the application lifecycle, and beforeControllerAction occurs too late.

Does anyone know how to either override this, or use some alternate means of applying logic before all incoming requests, including externally-bound actions, but after registering of the module to which the request has been made?

Please do let me know if you need any clarification on the above.