« Return to Thread: Zend Controller: get controller instance from within a plugin

Re: Zend Controller: get controller instance from within a plugin

by Ivan Shumkov :: Rate this Message:

Reply to Author | View in Thread

gMail-27 wrote:
Can I get an action controller instance from within a controller plugin (class MyPlugin extends Zend_Controller_Plugin_Abstract).

You may use response object:

class MyController ...
{
  protected $_layout = 'default';
   ...
  function getLayout()
  {
    return $_layout;
  }
  function postDispatch()
  {
     $this->getResponse()->setController($this);
  }
   ...
}

class My_Controller_Response_Http ...
{
  protected $_controller;
  ...
  function setController(Zend_Controller_Action $controller)
  {
    $this->_controller = $controller;
  }
  function getController()
  {
    return $this->_controller;
  }
  ...
}

class My_Controller_Plugin_Layout ...
{
  function ...
  {
      $layout = $this->getResponse()->getController()->getLayout();
  }
}
http://www.nabble.com/Layout-templates-tf3432215s16154.html#a9567943

 « Return to Thread: Zend Controller: get controller instance from within a plugin