zendframework/zend-navigation
Abandoned Zend Framework navigation component for building and managing navigation trees (menus, breadcrumbs, links, sitemaps). Repository moved to laminas/laminas-navigation; see Laminas docs for current usage.
The fastest way to get up and running with zend-navigation is:
navigation key
in your application configuration.Edit the application configuration file config/application.config.php:
<?php
return [
'modules' => [
'Zend\Router',
'Zend\Log',
'Zend\Navigation', // <-- Add this line
// ...
],
];
Add the container definition to your configuration file, e.g.
config/autoload/global.php:
<?php
return [
// ...
'navigation' => [
'default' => [
[
'label' => 'Home',
'route' => 'home',
],
[
'label' => 'Page #1',
'route' => 'page-1',
'pages' => [
[
'label' => 'Child #1',
'route' => 'page-1-child',
],
],
],
[
'label' => 'Page #2',
'route' => 'page-2',
],
],
],
// ...
];
Calling the view helper for menus in your layout script:
<!-- ... -->
<body>
<?= $this->navigation('default')->menu() ?>
</body>
<!-- ... -->
Once the zend-navigation module is registered, you can create as many navigation definitions as you wish, and the underlying factories will create navigation containers automatically.
Add the container definitions to your configuration file, e.g.
config/autoload/global.php:
<?php
return [
// ...
'navigation' => [
// Navigation with name default
'default' => [
[
'label' => 'Home',
'route' => 'home',
],
[
'label' => 'Page #1',
'route' => 'page-1',
'pages' => [
[
'label' => 'Child #1',
'route' => 'page-1-child',
],
],
],
[
'label' => 'Page #2',
'route' => 'page-2',
],
],
// Navigation with name special
'special' => [
[
'label' => 'Special',
'route' => 'special',
],
[
'label' => 'Special Page #2',
'route' => 'special-2',
],
],
// Navigation with name sitemap
'sitemap' => [
[
'label' => 'Sitemap',
'route' => 'sitemap',
],
[
'label' => 'Sitemap Page #2',
'route' => 'sitemap-2',
],
],
],
// ...
];
Container names have a prefix
There is one important point to know when using zend-navigation as a module: The name of the container in your view script must be prefixed with
Zend\Navigation\, followed by the name of the configuration key. This helps ensure that no naming collisions occur with other services.
The following example demonstrates rendering the navigation menus for the named
default, special, and sitemap containers.
<!-- ... -->
<body>
<?= $this->navigation('Zend\Navigation\Default')->menu() ?>
<?= $this->navigation('Zend\Navigation\Special')->menu() ?>
<?= $this->navigation('Zend\Navigation\Sitemap')->menu() ?>
</body>
<!-- ... -->
How can I help you explore Laravel packages today?