在没有顶级的情况下渲染 Zend Navigation 的活动分支

发布于 2024-09-15 07:13:10 字数 915 浏览 6 评论 0原文

我正在一个地方渲染 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 技术交流群。

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

发布评论

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

评论(3

半山落雨半山空 2024-09-22 07:13:10

如果我的问题正确,我就是这样做的:

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

仅渲染当前活动菜单的子菜单。

If I got your question right, this is how I do it:

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

Renders only the submenu of currently active menu.

坐在坟头思考人生 2024-09-22 07:13:10

我做了类似的事情。我的主导航是用这样的东西处理的...

$this->navigation()->menu()->setPartial('tabs.phtml');
echo $this->navigation()->menu()->render();

然后在我的 tabs.phtml 中我像这样迭代容器...

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

我希望这会有所帮助。

I do something similar. My main navigation is handled with something like this...

$this->navigation()->menu()->setPartial('tabs.phtml');
echo $this->navigation()->menu()->render();

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

I hope that helps a bit.

深居我梦 2024-09-22 07:13:10

我这样做:

<?php

// Render top-level elements
echo $this->navigation()->menu()->setMaxDepth(0);

// Render 2nd level elements for active element
echo $this->navigation()->menu()
        ->setOnlyActiveBranch(true)
        ->setRenderParents(false)
        ->setMinDepth(1);

?>

但这不是一个好的解决方案。每个级别最好有一个单独的菜单:

<!-- level 1 -->
<?php echo $this->navigation()->menu()->setMaxDepth(0); ?>


<!-- level 2 -->
<?php echo $this->navigation()->menu()->setOnlyActiveBranch(true)->setRenderParents(true)->setMinDepth(1)->setMaxDepth(1); ?>



<!-- level 3 -->
<?php echo $this->navigation()->menu()->setOnlyActiveBranch(true)->setRenderParents(false)->setMinDepth(2)->setMaxDepth(2); ?>

I do it this way:

<?php

// Render top-level elements
echo $this->navigation()->menu()->setMaxDepth(0);

// Render 2nd level elements for active element
echo $this->navigation()->menu()
        ->setOnlyActiveBranch(true)
        ->setRenderParents(false)
        ->setMinDepth(1);

?>

but this is not a good solution. Better one for each level as a separate menu:

<!-- level 1 -->
<?php echo $this->navigation()->menu()->setMaxDepth(0); ?>


<!-- level 2 -->
<?php echo $this->navigation()->menu()->setOnlyActiveBranch(true)->setRenderParents(true)->setMinDepth(1)->setMaxDepth(1); ?>



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