Is there any way to access the current controller or request object outside mvc in CakePHP(2.*)?
Basically I need to access the request object in a library that is designed for CakePHP but should function on its own as much as possible – in other words I’d like to avoid any unnecessary lib-specific initialization code in the controller itself to keep the.
I have written a component for this purpose but not all calls to the lib will be directly from the controller. I’d also like to avoid passing the $controller or $request variable around anywhere else but inside the lib.
I’ve never looked into CakePHP class loading much, but I can recall something about ClassRegistry from when CakePHP 1.3 was new. Soon after testing ClassRegistry in a controller action I found it to be empty(determined with ClassRegistry::keys() and pr()’ing directly from the class)
So, is there any friendly way to get the request object or should I resort to uglier methods?
Router::getRequest()should get you the CakeRequest instance.