您可以根据需要使用部分生成导航。
要在模板中显示导航:
<?php $partial = array('application/navigation/topnav.phtml', 'default') ?>
<?php $this->navigation('navigation')->menu()->setPartial($partial) ?>
<?php echo $this->navigation('navigation')->menu()->render() ?>
您的导航部分应该是这样的:
应用程序/导航/topnav.phtml
<ul class="nav">
<?php $count = 0 ?>
<?php foreach ($this->container as $page): ?>
<?php /* @var $page Zend\Navigation\Page\Mvc */ ?>
<?php // when using partials we need to manually check for ACL conditions ?>
<?php if( ! $page->isVisible() || !$this->navigation()->accept($page)) continue; ?>
<?php $hasChildren = $page->hasPages() ?>
<?php if( ! $hasChildren): ?>
<li <?php if($page->isActive()) echo 'class="active"'?>>
<a class="nav-header" href="<?php echo $page->getHref() ?>">
<?php echo $this->translate($page->getLabel()) ?>
</a>
</li>
<?php else: ?>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<span><?php echo $this->translate($page->getLabel()) ?></span>
</a>
<ul class="dropdown-menu" id="page_<?php echo $count ?>">
<?php foreach($page->getPages() as $child): ?>
<?php // when using partials we need to manually check for ACL conditions ?>
<?php if( ! $child->isVisible() || !$this->navigation()->accept($child)) continue; ?>
<li>
<a href="<?php echo $child->getHref() ?>">
<?php echo $this->translate($child->getLabel()) ?>
</a>
</li>
<?php endforeach ?>
</ul>
</li>
<?php endif ?>
<?php $count++ ?>
<?php endforeach ?>
</ul>
显然,这是一个简单的示例,不会处理任意数量的导航级别,并且您需要添加一些额外的类名等以使其与 Bootstrap 完美配合,但您明白了。