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

发布于 2024-12-11 18:14:16 字数 979 浏览 0 评论 0原文

尝试打印 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) 之类的

有什么想法吗?谢谢

trying to print out about 3 menus on ZF. Currently I can't even get one out. Not quite sure what's going on and why theres no mention of how to get it working on the manual.

So this is my layout.phtml:

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

Not entirely sure if this is how I'm meant to create the navigation but I plan on changing the routes eventually for localization:

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

I've got this in my bootstrap:

    protected function _initNavigation() 
{

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

}

Only the content displays... Wanted to be able to have different menu types like... show(topMenu), show(loggedinSideMenu) sort of thing

Any idea? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坐在坟头思考人生 2024-12-18 18:14:16

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

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

<?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_Application 有一个 用于导航的资源插件 然而它只能处理一个容器,这对你没有真正的帮助。我会在您的 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) ?>

Couple of things here...

First, to display navigation, use the appropriate helper. In your layout file...

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

See http://framework.zend.com/manual/en/zend.navigation.introduction.html and http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation

Secondly, Zend_Application has a resource plugin for navigation however it's only able to handle one container which doesn't really help you. I'd recommend something like this in your Bootstrap method...

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

Then, in your layout

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

<!-- side menu -->
<?php echo $this->navigation()->menu()
    ->renderMenu($this->layout()->loggedInSideMenu) ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文