Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to use the navigation helper to build my navigation menus using Acl. The Acl part I have working fine.

I now want to be able to display a few different types of navigation. E.g. admin-nav, side-nav, new-nav, etc. I cannot find anything about this in the docs. Only how to set the navigation and then use that one navigation object repeatedly within a layout or view.

I tried something similar to this - having two different containers, with different arrays of pages, then setting these containers in the registry. Then from within my view and/or layout calling navigation and passing it a container:

<?php echo $this->navigation(Zend_Registry::get("news-nav")) ?>

The above is called in my news view, the following is called in my layout

<?php echo $this->navigation(Zend_Registry::get("admin-nav")) ?>

This works fine for all my pages, apart from the news page. On my news page the nav for news is displayed twice, once in the layout and once in the news view. The admin nav is never displayed and seems to be overwritten by the news nav.

I could be going about this completely the wrong way, if so please let me know a better way. If this method seems fine, can someone help me sort out why the news nav is being displayed in the layout and in the news view.

Thanks for your time

Jake

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
231 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have had this exact same issue. I just create multiple instances of Zend_Navigation_Container in my controllers for each of the menus I need, pass them to the view and then render them by passing the objects directly to the menu render method. As follows:

In the controller:

$this->view->menu1 = new Zend_Navigation_Container();
$this->view->menu2 = new Zend_Navigation_Container();

In the view:

$this->navigation()->menu()->renderMenu($this->menu1);
$this->navigation()->menu()->renderMenu($this->menu2);

You could even customise each one (by inserting method calls after the initial menu() call:

$this->navigation()->menu()->setUlClass('my_first_menu')->renderMenu($this->menu1);
$this->navigation()->menu()->setUlClass('my_second_menu')->renderMenu($this->menu2);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...