Zend_Navigation用于在Layout中显示不同的菜单

时间:2011-10-25 19:17:30

标签: php model-view-controller zend-framework zend-navigation

尝试在ZF上打印出约3个菜单。目前我甚至不能得到一个。不太清楚发生了什么,为什么没有提到如何使它在手册上工作。

所以这是我的layout.phtml:

<body>
    <?php echo $this->layout()->nav; ?>
    <?php echo $this->layout()->content; ?>
</body>

不完全确定这是否是我创建导航的方式,但我计划最终更改路线以进行本地化:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <nav>
        <register>
            <label>Register</label>
            <controller>register</controller>
            <action>index</action>
        </register>
</nav>
</config>

我在自助训​​练中得到了这个:

    protected function _initNavigation() 
{

    // Navigation
    $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
    $container = new Zend_Navigation($config);

}

只有内容显示...想要能够有不同的菜单类型,如... show(topMenu),show(loggedinSideMenu)等等

有什么想法吗?感谢

1 个答案:

答案 0 :(得分:1)

这里有几件事......

首先,要显示导航,请使用适当的帮助程序。在你的布局文件......

<?php echo $this->navigation()->menu()
    ->renderMenu($zendNavigationContainer) ?>

请参阅http://framework.zend.com/manual/en/zend.navigation.introduction.htmlhttp://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation

其次,Zend_Applicationresource plugin for navigation但是它只能处理一个对你没有帮助的容器。我会在你的Bootstrap方法中推荐这样的东西......

protected function _initNavigation()
{
    // get config and create containers as before

    // bootstrap layout resource and retrieve it
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');

    // add containers as layout properties
    $layout->topMenu = $topMenuContainer;
    $layout->loggedInSideMenu = $sideMenuContainer;
}

然后,在你的布局中

<!-- top menu -->
<?php echo $this->navigation()->menu()
    ->renderMenu($this->layout()->topMenu) ?>

<!-- side menu -->
<?php echo $this->navigation()->menu()
    ->renderMenu($this->layout()->loggedInSideMenu) ?>