Hello to everyone,
I have got a problem (or a bug?) with the Zend_View component.
I have this front controller plugin:
class My_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
{
protected $_stack;
public function dispatchLoopStartup( Zend_Controller_Request_Abstract $request
)
{
$modules = Zend_Controller_Front::getInstance()->getControllerDirectory();
$stack = $this->getStack();
foreach ($modules as $moduleName => $modulePath) {
$leftMenuRequest = clone( $request );
$leftMenuRequest->setDispatched(false);
$leftMenuRequest->setModuleName( $moduleName )
->setControllerName('menu')
->setActionName('index');
$stack->pushStack($leftMenuRequest);
}
}
/**
Returns the stack using Zend_Controller_Plugin_ActionStack
**/
public function getStack()
{...}
}
With the application having two modules, the same view gets rendered two times
(for each module) (and namely the view from the last module that is registered
). I mention that the actions can have no code, and the result is the same.
What could be the problem?
Thanks in advance,
Andrei
--- On Thu, 4/30/09, Andrei Iarus <[email protected]> wrote:
From: Andrei Iarus <[email protected]>
Subject: Re: [fw-general] Menu in ZF: Controller Plugin with postDispatch method
To: "Zend Framework" <[email protected]>
Date: Thursday, April 30, 2009, 8:09 PM
Hello everyone,
THe solution is to use the dispatchLoopStartup method in the
Controller_Plugin_Menu, and there to use the Zend_Controller_Plugin_ActionStack
plugin, as this plugin "operates as a postDispatch plugin"(from the manual).
This means that all the variables set from the requested by the browser action,
will be available to the menu controller.
--- On Thu, 4/30/09, lightflowmark <[email protected]> wrote:
From: lightflowmark <[email protected]>
Subject: Re: [fw-general] Menu in ZF: Controller Plugin with postDispatch method
To: [email protected]
Date: Thursday, April 30, 2009, 4:12 PM
The way I do something similar is to run code in dispatchLoopStartup like
$viewRenderer =
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->init();
$view = $viewRenderer->view;
$this->_view = $view;
// set up common variables for the view
$view->originalModule = $request->getModuleName();
$view->originalController = $request->getControllerName();
$view->originalAction = $request->getActionName();
I also set up my actionstack in dispatchLoopStartup. In my menuAction, I
can then compare my menu items with $view->originalAction, etc. and colour
them appropriately.
Don't know if this is a good solution or not, but it is working for me.
--
View this message in context:
http://www.nabble.com/Menu-in-ZF%3A-Controller-Plugin-with-postDispatch-method-tp23306086p23315051.html
Sent from the Zend Framework mailing list archive at Nabble.com.