Zend Framework - 多板导航块

2021-12-29 00:00:00 navigation php zend-framework

我想使用导航助手通过 Acl 构建我的导航菜单.我的 Acl 部分工作正常.

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

我现在希望能够显示几种不同类型的导航.例如.admin-nav、side-nav、new-nav 等.我在文档中找不到任何关于此的信息.只有如何设置导航,然后在布局或视图中重复使用该导航对象.

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.

感谢您的时间

杰克

推荐答案

我遇到了完全相同的问题.我只是在我的控制器中为我需要的每个菜单创建多个 Zend_Navigation_Container 实例,将它们传递给视图,然后通过将对象直接传递给菜单渲染方法来渲染它们.如下:

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:

在控制器中:

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

在视图中:

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

您甚至可以自定义每一个(通过在初始 menu() 调用后插入方法调用:

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);

相关文章