depa / middleware-navigation
The middleware navigation is a PSR-15 middleware that provides navigation functionality to a Zend Expressive application
Requires
- knplabs/knp-menu: ^2.3
- psr/container: ^1.0
- psr/http-server-middleware: ^1.0
- zendframework/zend-servicemanager: ^3.4
README
Installation
Run the following to install this library:
$ composer require depa/middleware-navigation
Documentation
After installing the module, you have to implement the navigation-middleware into your pipeline, so you basically add this line above the RouteMiddleware:
$app->pipe(depa\NavigationMiddleware\Middleware\NavigationMiddleware::class);
To create a navigation, use the navigation.global.php (it's inside the config folder) as your basic (put it into config\autoload)
The basic structure of a menu-item must look like this:
'{navigation_Name}' => [ 'route' => '{route_name}', //route-name which is set in routes.php ]
if you want to add attributes to a menu-item (to the ul element), do this:
'{navigation_Name}' => [ 'attributes' => [...], //possibilitys in attributes-table described (at the bottom of the doc) ]
if you want to add link-attributes to a menu-item (to the a element), do this:
'{navigation_Name}' => [ 'linkAttributes' => [...], //possibilitys in link-attributes-table described (at the bottom of the doc) ]
if you want to add child-items to a menu-item, do this (you can use as many as you want):
'{navigation_Name}' => [ 'childs' => [...], //build the same as a normal menu-item ]
if you want to force a link-direction to an item then add this:
'{navigation_Name}' => [ 'uri' => '{https://www.designpark.de}', ]
a menu-item which contains any of the given examples could look like this:
'{navigation_Name}' => [ 'route' => '{route_name}', 'uri' => '{https://www.designpark.de}', 'attributes' => [ 'id' => '{some_id}', 'class' => ['{class1} {class2}'], ], 'linkAttributes' => [ 'id' => '{some_id}', 'class' => '{class_1} {class2}', ], 'childs' => [ '{childNavigation_Name}' => [ 'route' => '{route_name}', 'uri' => '{https://www.designpark.de}', 'attributes' => [], 'linkAttributes' => [], 'childs' => [], ] ] ]
The example provided above would output the following HTML:
<ul>
<li id="{some_id} class="{class1 class2} first last">
<a href="{https://www.designpark.de}">{navigationName}</a>
<ul class="menu_level_1">
<li class="first last">
<a href="{https://www.designpark.de}">{childNavigationName}</a>
</li>
</ul>
</li>
</ul>
which would look like this:
-
{navigationName}
- {childNavigationName}
Attributes you could use and what they do:
Attribute | Description | Example |
---|---|---|
Id | Sets the id of the element | 'id' => 'some_id' |
class | Sets the classes of the elements | 'class' => 'class1 class2' |
Link-Attributes you could use and what they do:
Attribute | Description | Example |
---|---|---|
Id | Sets the id of the element | 'id' => 'some_id' |
Class | Sets the classes of the element | 'class' => 'class1 class2' |
Target | Sets the target-window of the element | 'target' => '_blank' |
we did not listed every link-/attribute, take a closer look at knpLabs/KnpMenu for more informations!
Credits
This bundle is inspired by Zend Framework. It has been developed by designpark.
License
The MIT License (MIT). Please see License File for more information.