在没有顶级的情况下渲染 Zend Navigation 的活动分支
我正在一个地方渲染 Zend Navigation 对象的顶级元素,如下所示:
echo $this->navigation()->menu()->setMaxDepth(0);
How do I render the navigation tree from the secondary on down for the active Branch?我尝试创建一个循环 $this->container
对象的部分,但我不知道如何确定当前项目是否是活动分支。一旦我确定它是活动分支,如何呈现菜单?我这样做是否很困难并且错过了一些明显的事情?
谢谢!
更新:
我接受了一个解决方案,因为这就是我使用的解决方案,但我也想提供我的实际问题的答案,以供参考。 ($this
是视图对象)
// Find the active branch, at a depth of one
$branch = $this->navigation()->findActive($this->nav, 1, 1);
if (0 == count($branch)) {
// no active branch, find the default branch
$pages = $this->nav->findById('default-branch')->getPages();
} else {
$pages = $branch['page']->getPages();
}
$this->subNav = new Zend_Navigation($pages);
然后可以使用 $this->subNav
来呈现子菜单。
I am rendering the top-level elements of a Zend Navigation object in one place like this:
echo $this->navigation()->menu()->setMaxDepth(0);
How do I render the navigation tree from the second level on down for the active branch? I've tried creating a partial that loops the $this->container
object, but I don't know how to determine if my current item is the active branch. Once I've determined that it's the active branch how do I render the menu? Am I doing this the hard way and missing something obvious?
Thanks!
UPDATE:
I accepted a solution because that's what I used, but I also would like to provide the answer to my actual question, for reference sake. ($this
is the view object)
// Find the active branch, at a depth of one
$branch = $this->navigation()->findActive($this->nav, 1, 1);
if (0 == count($branch)) {
// no active branch, find the default branch
$pages = $this->nav->findById('default-branch')->getPages();
} else {
$pages = $branch['page']->getPages();
}
$this->subNav = new Zend_Navigation($pages);
$this->subNav
can then be used to render the sub-menu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我的问题正确,我就是这样做的:
仅渲染当前活动菜单的子菜单。
If I got your question right, this is how I do it:
Renders only the submenu of currently active menu.
我做了类似的事情。我的主导航是用这样的东西处理的...
然后在我的 tabs.phtml 中我像这样迭代容器...
我希望这会有所帮助。
I do something similar. My main navigation is handled with something like this...
Then in my tabs.phtml I iterate over the container like so...
I hope that helps a bit.
我这样做:
但这不是一个好的解决方案。每个级别最好有一个单独的菜单:
I do it this way:
but this is not a good solution. Better one for each level as a separate menu: