ZF2 - multiple nav menus using the navigation view helper

不打扰是莪最后的温柔 提交于 2019-12-04 11:42:58

The menu, breadcrumbs, sitemap and links helpers are registered as plugins. If you call $this->navigation('main_navigation') for the first time, the Zend\View\Helper\Navigation creates the container "main_navigation". If you then call menu() for the first time the Zend\View\Helper\Navigation\Menu object is created and directly the container is injected.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!