Goran Juric wrote:
>
>
>
> drj201 wrote:
>>
>> Hi all,
>>
>> Ive been following the method outlined here to add Controller specific
>> navigation menus to my layout view:
>>
>> http://teethgrinder.co.uk/perm.php?a=Zend-Framework-Menus-Navigation
>>
>> Firstly, what is your view on this approach? Adding an actionStack call
>> to every controller seems long winded especially if the majority use a
>> standard menu i.e. defaultmenuAction in the NavController.
>>
>> Also using this method I am encountering a problem with the use of
>> _forward() in my actions.
>>
>> When calling a _forward from one action to another within the same
>> controller the menu action is added to the actionStack twice (once for
>> initial init() and then for each forward). How would you propose I stop
>> this easily? Is there a way of detecting if the actionStack currently has
>> the call to the action in the NavController and thus doesnt add it again?
>> Back to my original question... is there a better way entirely?
>>
>> Thanks for your help.
>>
>> David
>>
>
>
> Why don't you use a view helper for this task? You can define and pass
> controller specific actions in the init() method of the controller and
> display them in a view.
>
> Regards,
>
> Goran Juric
> http://gogs.info/
>
Thanks for your reply. Im not sure I follow your suggestion? What are you
proposing with the use of a view helper?
Im trying to follow the example from the Zend_Layout documentation that
states:
------------
"As an example, let's say your code first hits FooController::indexAction(),
which renders some content to the default response segment, and then
forwards to NavController::menuAction(), which renders content to the 'nav'
response segment. Finally, you forward to CommentController::fetchAction()
and fetch some comments, but render those to the default response segment as
well (which appends content to that segment). Your view script could then
render each separately:
<body>
<!-- renders /nav/menu -->
<div id="nav"><?= $this->layout()->nav ?></div>
<!-- renders /foo/index + /comment/fetch -->
<div id="content"><?= $this->layout()->content ?></div>
</body>
This feature is particularly useful when used in conjunction with the
ActionStack action helper and plugin, which you can use to setup a stack of
actions through which to loop, and thus create widgetized pages. "
------------
I have this working based on an example here:
http://teethgrinder.co.uk/perm.php?a=Zend-Framework-Menus-Navigation
The problem is that when using a _forward() to another action within the
same controller the init() gets called every forward thus resulting in the
$this->_helper->actionStack('menu', 'navigation') getting called every time.
This means the navigation menuAction gets rendered a number of times when
obviously it only wants to render once...
So ultimately how can I detect if the current controller init() has been
called as the result of a _forward() and thus then not add the menuAction
to the stack...?
Also if there is a better simplified way of doing this i'd be enlightened to
know!
Thanks,
David
--
View this message in context:
http://www.nabble.com/ActionStack-and-_forward%28%29-tp20469986p20520241.html
Sent from the Zend Framework mailing list archive at Nabble.com.