Reputation: 1001
I hope I had made me clear in my question!
I would like to access the getControllerName() and getActionName() inside _initVars(). This is what I'm trying to do:
protected function _initVars()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$view->theme = 'MY_THEME';
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
echo '<pre>';
print_r($front->getRequest());
echo '</pre>';
exit;
return $view;
}
I'm getting no response, the fields controllername and actionname are returning empty, this is what I get in the return:
Zend_Controller_Front Object
(
[_baseUrl:protected] =>
[_controllerDir:protected] =>
[_dispatcher:protected] => Zend_Controller_Dispatcher_Standard Object
(
[_curDirectory:protected] =>
[_curModule:protected] => default
[_controllerDirectory:protected] => Array
(
[default] => /var/www/proj_rodrigo/application/controllers
)
[_defaultAction:protected] => index
[_defaultController:protected] => index
[_defaultModule:protected] => default
[_frontController:protected] =>
[_invokeParams:protected] => Array
(
)
It's just a part of the code, the necessary things are there, in the old schema of Zend I could be capable to do it calling Zend_Front_Controller, but now I don't know more how to use it.
Appreciate any help! Best regards and sorry for my BAD English.
To fix this issue, I add the postDispatche at my plugin:
public function postDispatch(Zend_Controller_Request_Abstract $request) {
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$layout = $bootstrap->getResource('layout');
$view = $layout->getView();
$view->controller = $this->getRequest()->getControllerName();
$view->action = $this->getRequest()->getActionName();
}
Thanks again!
Upvotes: 1
Views: 1194
Reputation: 14184
It looks like this code is in the Bootstrap
class. Since Bootstrap
code runs before the routing - in, fact this stage is where routing is often defined - the controller and action are not yet determined.
If you want to get that info, you need to create a front-controller plugin implementing an early-running method - that runs after routing has set the controller and action - like routeShutdown()
or dispatchLoopStartup()
or preDispatch()
.
Check out: ZF Dispatch Overview (PDF)
Upvotes: 1