List Info

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




Zend Controller: get controller instance from within a plugin
user name
2007-03-28 18:26:53
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 ?


Re: Zend Controller: get controller instance from within a plugin
user name
2007-03-29 02:33:47
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

View this message in context: Re: Zend Controller: get controller instance from within a plugin
Sent from the Zend Framework mailing list archive at Nabble.com.
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )