Zend Controller: get controller instance from within a plugin

2 messages Options
Embed this post
Permalink
Stoyan Kyosev

Zend Controller: get controller instance from within a plugin

Reply Threaded More More options
Print post
Permalink
Hello all,

Can I get an action controller instance from within a controller
plugin (class MyPlugin extends Zend_Controller_Plugin_Abstract).
The method, described in the manual, seems to be no longer valid:

        $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
        $controller = $dispatcher->getController($request);

I have the following:

class IndexController extends Zend_Controller_Action {

        public $layout = 'default';

        ......
and I need to access the value of $layout from the plugin, therefore I
am trying to get an IndexController.

Any advise ?

Ivan Shumkov

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

Reply Threaded More More options
Print post
Permalink
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