Running certain function before the controller init function

I am using ReflectionClass to somehow make on-the-fly classes to run when the application loads so basically when i load the index controller i would like to run another class first that extends the indexcontroller instead.

How can i run something before the request is sent to make it load another controller file instead of the one it should load, But at that time i need to know which controller it is trying to load.


What’s about overriding


of CWebApplication?

Just an idea.

modules have a “beforeControllerAction” inherited by CWebModule. But, I don’t know how to do it for the main application.

have a look at the onBeginRequest Event of CApplication, maybe you can hook in

Does onbeginRequest run after the system knows which module/controller/action to run?

I think CApplication::createController() needs to be overridden/refactored for this purpose.

createController() is responsible for parsing the route and create modules (if any) as well as the requested controller.

I had an idea about a factory object to be specified in controllerMap. The route could be like .../site/module and_or factory/controller/action/params. Of course the controller/action/params information has to be propagated to the factory method.