问题描述
我正在这样一个地方渲染Zend Navigation对象的顶级元素:
I am rendering the top-level elements of a Zend Navigation object in one place like this:
echo $this->navigation()->menu()->setMaxDepth(0);
如何为活动分支从第二层向下渲染导航树?我尝试创建一个循环$this->container
对象的局部对象,但是我不知道如何确定当前项目是否为活动分支.确定是活动分支后,如何呈现菜单?我是不是很难做到这一点,却缺少明显的东西?
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?
谢谢!
更新:
我接受了一个解决方案,因为那是我使用的解决方案,但是我也想提供我的实际问题的答案,以供参考. ($this
是视图对象)
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
呈现子菜单.
$this->subNav
can then be used to render the sub-menu.
推荐答案
我做了类似的事情.我的主要导航方式是这样的...
I do something similar. My main navigation is handled with something like this...
$this->navigation()->menu()->setPartial('tabs.phtml');
echo $this->navigation()->menu()->render();
然后在我的tabs.phtml中像这样遍历容器...
Then in my tabs.phtml I iterate over the container like so...
if (count($this->container)) {
foreach($this->container as $page) {
if ($page->isVisible()) {
if ($page->isActive(true)) {
$subcontainer = $page->getPages();
foreach($subcontainer as $subpage) {
// echo my link
}
}
}
}
}
我希望能有所帮助.
这篇关于在没有顶层的情况下渲染Zend导航的活动分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!