### 安装依赖包
```
composer require zendframework/zend-navigation
```
**设置服务管理器**
> config/autoload/navigation.global.php
```php
<?php
use Zend\Navigation\ConfigProvider;
return [
'service_manager' => (new ConfigProvider())->getDependencyConfig(),
];
```
### 模块配置
> module/Application/config/module.config.php
改回默认首页
```php
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class, // <-- change back here
'action' => 'index',
],
],
],
```
设定导航站点地图
```php
'navigation' => [
'default' => [
[
'label' => 'Home',
'route' => 'home',
],
[
'label' => 'Album',
'route' => 'album',
'pages' => [
[
'label' => 'Add',
'route' => 'album',
'action' => 'add',
],
[
'label' => 'Edit',
'route' => 'album',
'action' => 'edit',
],
[
'label' => 'Delete',
'route' => 'album',
'action' => 'delete',
],
],
],
],
],
```
### 视图
**修改布局模板**
> module/Application/view/layout/layout.phtml
```php+HTML
<div class="collapse navbar-collapse">
<?php // update to: ?>
<?= $this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setUlClass('nav navbar-nav') ?>
</div>
<!--- ... --->
<div class="container">
<?php // Update to: ?>
<?= $this->navigation('navigation')
->breadcrumbs()
->setMinDepth(0)
->setPartial('partial/breadcrumb') ?>
<?= $this->content ?>
</div>
```
**新增面包屑模板**
> module/Application/view/partial/breadcrumb.phtml
```php+HTML
<ul class="breadcrumb">
<?php
// iterate through the pages
foreach ($this->pages as $key => $page):
?>
<li>
<?php
// if this isn't the last page, add a link and the separator:
if ($key < count($this->pages) - 1):
?>
<a href="<?= $page->getHref() ?>"><?= $page->getLabel() ?></a>
<?php
// otherwise, output the name only:
else:
?>
<?= $page->getLabel() ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
```