0

I need to create my own resource which sends some information to Zend_View instance which depends on currently working controller and action. I've got this code:

$view = $bootstrap->getResource('layout')->getView();
$front = $bootstrap->getResource('frontController');
$front->setRequest(new Zend_Controller_Request_Http);

$controller = $front->getRequest()->getControllerName();
$action = $front->getRequest()->getActionName();

$view->headTitle(
    $this->getPage()
        ->setController($controller)
        ->setAction($action)
        ->getTitle()
);

but $controller and $action are empty. I don't know if I'm doing something wrong or getting access to controller and action names is impossible in resource.

hakre
  • 193,403
  • 52
  • 435
  • 836
Kacper Kołodziej
  • 698
  • 1
  • 9
  • 23

1 Answers1

1

You can't access the request object in a resource because it doesn't exist yet. The request object gets set during dispatch which happens after the application has been bootstrapped. It sounds like this logic should be moved to a controller plugin instead.

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
  • Thanks. I've checked `Zend_Controller_Front` on the Zend API Docs and I have seen `dispatch` function which needs `Zend_Controller_Action_Abstract` argument, but I wasn't sure if there is any way to get access to names of controller and action. – Kacper Kołodziej Aug 15 '12 at 13:46