Rather than looping through the registered plugins, the Front controller
exposes a getPlugin method which you can use to retrieve an instance of
a plugin by class name.
tony stamp wrote:
Thanks for the reply Jason.
The actionstack was definitely the right way to go - i managed to develop a
solution using it, so thanks for pointing it out.
An explanation, in case someone has the same problem:
The actionstack is only loaded (lazy-loaded) when the actionstack helper is
used within a controllers pre/postDispatch method - it is not a plugin
loaded by default, which in my situation meant i might as well have left the
calls to the MenuFactory in the postDispatch method.
To pass on the request data from the first request to the second simply
meant i needed to initialise the action stack as a front controller plugin
in my bootstrap:
$frontController->registerPlugin(new
Zend_Controller_Plugin_ActionStack(Zend_Registry::getInstance()));
Then in my layout:
<?php echo $this->action('index', 'submenu'); ?>
And finally, the SubmenuController. If it discovers an instance of the
actionstack, it gets the request from the plugin (not the SubmenuControllers
$this->getRequest(), which would be a new/fresh request):
class SubmenuController extends Zend_Controller_Action
{
public function indexAction(){
$frontController =
Zend_Controller_Front::getInstance();
foreach($frontController->getPlugins() as $plugin){
if($plugin instanceof
Zend_Controller_Plugin_ActionStack ){
$menuFactory = new
Menu_Factory_Site($plugin->getRequest());
$this->view->subMenu =
$menuFactory->getSubMenu();
}
}
}
}
...and the correct submenu is loaded and assigned to the view!