php - 在没有顶级的情况下呈现 Zend Navigation 的事件分支

标签 php zend-framework zend-navigation

我正在像这样在一个地方呈现 Zend Navigation 对象的顶级元素:

echo $this->navigation()->menu()->setMaxDepth(0);

如何为事件分支从第二层向下呈现导航树?我已经尝试创建一个循环 $this->container 对象的部分,但我不知道如何确定我的当前项目是否是事件分支。一旦我确定它是事件分支,我该如何呈现菜单?我这样做是不是很费力并且遗漏了一些明显的东西?

谢谢!


更新:

我接受了一个解决方案,因为这是我使用的解决方案,但我也想提供我实际问题的答案,以供引用。 ($this 是 View 对象)

// 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 然后可用于呈现子菜单。

最佳答案

如果我答对了你的问题,我就是这样做的:

print $this->navigation()->menu()->renderMenu(null, array(
    'minDepth' => 1,
    'maxDepth' => 1,
    'onlyActiveBranch' => true,
    'renderParents' => false));

仅呈现当前事件菜单的子菜单。

关于php - 在没有顶级的情况下呈现 Zend Navigation 的事件分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3496763/

相关文章:

javascript - 如何在JS中使用ajax请求的结果?

php - Zend 选择所有列

php - Zend Framework 2如何使用连接从多个表中获取列?

php - Zend 导航和 Zend ACL

PHP foreach 插入语句问题与数组

php - 在隐藏输入中使用 base64_encode 与 json_encode 传递编码数据

php - 如何使用 zend_auth 作为插件

php - Zend View Helper Navigation 移除事件分支,因此面包屑不会显示

php - Zend_Navigation 加载失败

php - 处理对同一 url Laravel 5 的多个发布请求