As you've discovered, the action view helper creates an entire new dispatching/request environment, and returns the result of that.

In order to achieve something closer to the results you'd like, use the ActionStack action helper.
<http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.actionstack>
It will allow to to push additional actions on to the current request/dispatching instance.

However, due to the nature of the request object, the controller name will still reflect the currently executing action, if I'm not mistaken. One possible way to get around this would be to pass any relevant information you may need as a parameter to the action (the fourth argument on the actionStack helper).

While not completely related, an example would be the way I handle a request to a resource that requires authentication within an application. In the preDispatch hook, it is determined if the user is logged in or not, and if no, the current request object is cloned, and passed as a parameter to a _forward call to the action that handles authentication. This way, I'm able to redirect the user back to the initially requested action upon successful authentication.

There is one more possibility I just remembered... You always have access to the ActionStack front controller plugin, <http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard.actionstack> and can access the full stack, and analyze that data to determine what's been done already.

tony stamp wrote:
Hello

I am interested in using an action helper within my view to load the
view-specific sub menu. At the moment, i am calling a menu factory during
the controllers post dispatch method to assign the menu (identified by the
requests controller name) to the view.

What i would like to do instead is simply call a SubmenuController via an
action helper and have the submenu automatically loaded from within my
layout.

The only problem i am having, is that when i use the action helper in my
layout:
<?php echo $this->action('index', 'Submenu'); ?>
... i believe the request is fired off as a separate request, not as a
continuation of the current request. This means that the method i use to
identify the current controller is no longer valid, as
$request->getControllerName() will always be SubmenuController.

Is it possible to forward the request object via an action helper? Or is
there any other / better way to make the above possible?

Reply via email to