ZF2 - multiple nav menus using the navigation view helper(ZF2 - 使用导航视图助手的多个导航菜单)
问题描述
我正在尝试将主导航与子菜单结合使用以进行更具体的导航.
I am trying to use a main navigation in combination with a submenu for more specific navigating.
在我的 layout 中,我这样调用视图助手:
In my layout I am calling the view helper like this:
$this->navigation('main_navigation')->menu()
在我的观点中,我这样称呼它:
and in my view I am calling it like this:
$this->navigation('sub_navigation')->menu()
问题是,每当我调用 navigation()
视图助手 不止一次,它只输出 second一个 在两个地方.换句话说,它正在为 both 主导航 和 子导航菜单打印 subnav.
The problem is that whenever I call the navigation()
view helper a more than once, it just outputs the second one in both places. In other words, it's printing the subnav for both the main nav and the subnav menus.
我的合并配置如下所示:
My merged config looks like this:
'navigation' => array(
'main' => array(
'home' => array(
'label' => 'Home',
'route' => 'myroute',
),
'somepage' => array(
'label' => 'Me',
'route' => 'somepage'
)
),
'sub' => array(
'test' => array(
'label' => 'Test',
'route' => 'myroute',
'action' => 'test'
),
'other-test' => array(
'label' => 'Other Test',
'route' => 'myroute',
'action' => 'other-test'
)
)
)
如何使用 navigation
视图助手,以便它为每次调用打印正确的菜单?
How do I use the navigation
view helper so that it will print the correct menu for each call?
推荐答案
menu
、breadcrumbs
、sitemap
和links
助手注册为插件.如果您第一次调用 $this->navigation('main_navigation')
,ZendViewHelperNavigation
会创建容器main_navigation".如果你然后调用 menu()
第一次 ZendViewHelperNavigationMenu
对象被创建直接 容器被注入.
The menu
, breadcrumbs
, sitemap
and links
helpers are registered as plugins. If you call $this->navigation('main_navigation')
for the first time, the ZendViewHelperNavigation
creates the container "main_navigation". If you then call menu()
for the first time the ZendViewHelperNavigationMenu
object is created and directly the container is injected.
这表明了缺陷:如果你现在调用 $this->navigation('sub_navigation')
,导航容器会在 navigation()
视图助手中加载.当您随后调用 menu()
时,菜单视图助手已经创建.因此不再注入新容器.
This indicates the flaw: if you call $this->navigation('sub_navigation')
now, the navigation container is loaded in the navigation()
view helper. When you then call menu()
, the menu view helper is already created. So the new container is not injected anymore.
显然这是代码库中的一个错误.有一个快速解决方法:菜单助手也可以接受容器字符串:
Clearly this is a bug in the code base. There is one quick fix: the menu helper can also accept the container string:
<?php echo $this->navigation()->menu('main_navigation'); ?>
<?php echo $this->navigation()->menu('sub_navigation'); ?>
我已经提交了一个关于它的问题,这个错误将被修复.
I have filed an issue about it and the bug will be fixed.
这篇关于ZF2 - 使用导航视图助手的多个导航菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ZF2 - 使用导航视图助手的多个导航菜单
基础教程推荐
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01