0

我在 zend2 中创建了一个菜单,它到目前为止有效。完美。

- Parent 1
-- Child Page 1
-- Child Page 2
-- Child Page 3
- Parent 2
-- Child Page 1
-- Child Page 2
-- Child Page 3
- Parent 3
-- Child Page 1
-- Child Page 2
-- Child Page 3

现在我只想在父页面处于活动状态时渲染子页面。假设 Parent 2 将处于活动状态,呈现的菜单将如下所示:

- Parent 1
- Parent 2
-- Child Page 1
-- Child Page 2
-- Child Page 3
- Parent 3

那是我的 global.php 配置文件

return array(
    'navigation' => array(
        'default' => array(
            array(
                'label' => 'Parent 1',
                'controller' => 'controllerone',
                'pages' => array(
                    array(
                        'label' => 'Page1',
                        'controller' => 'controllerone',
                        'action' => 'page-one',
                    ),
                    array(
                        'label' => 'Page2',
                        'controller' => 'controllerone',
                        'action' => 'page-two',
                    ),
                    array(
                        'label' => 'Page3',
                        'controller' => 'controllerone',
                        'action' => 'page-one',
                    )
                ),
            ),
            array(
                'label' => 'Parent 2',
                'controller' => 'controllertwo',
                'pages' => array(
                    array(
                        'label' => 'Page1',
                        'controller' => 'controllertwo',
                        'action' => 'page-one',
                    ),
                    array(
                        'label' => 'Page2',
                        'controller' => 'controllertwo',
                        'action' => 'page-two',
                    ),
                    array(
                        'label' => 'Page3',
                        'controller' => 'controllertwo',
                        'action' => 'page-one',
                    )
                ),
            ),
            array(
                'label' => 'Parent 3',
                'controller' => 'controllerthree',
                'pages' => array(
                    array(
                        'label' => 'Page1',
                        'controller' => 'controllerthree',
                        'action' => 'page-one',
                    ),
                    array(
                        'label' => 'Page2',
                        'controller' => 'controllerthree',
                        'action' => 'page-two',
                    ),
                    array(
                        'label' => 'Page3',
                        'controller' => 'controllerthree',
                        'action' => 'page-one',
                    )
                ),
            ),
        )
    ),
    'service_manager' => array(
        'factories' => array(
            'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
        ),
    ),
);

这就是我在布局中呈现导航的方式

<?php
echo $this
    ->navigation('navigation')
    ->menu();
?>

任何帮助将非常感激!

4

2 回答 2

0

您可以使用自定义视图模板和调用renderPartial()方法,甚至更好地扩展Zend\View\Helper\Navigation\Menu.

您基本上必须只为非活动分支调用renderMenu()带有选项的父级。$maxDepth = 0

您可以使用很多方法来 ie Zend\View\Helper\Navigation\AbstractHelper::findActive()

于 2013-06-05T14:50:10.377 回答
-1

正如在 irc 上的#zftalk 中发布的那样......您缺少将菜单助手设置为仅呈现活动分支,文档在这里: http: //framework.zend.com/manual/2.2/en/modules/zend .navigation.view.helper.menu.html


<?php
echo $this
    ->navigation('navigation')
    ->setOnlyActiveBranch(true)
    ->menu();
?>

应该可以解决您的问题

于 2013-06-05T13:35:13.813 回答