Create a HTML menu and breadcrumb menu items from a PHP array
Installation
Installation is available via Composer/Packagist:
composer require adamb/menu-builder
License
This software is distributed under the MIT license. Please read LICENSE for information on the
software availability and distribution.
Basic Usage
Make a new instance of the Navigation menu builder
<?php
$navigation = new Menu\Navigation();
Add some menu items
$navigation->addLink('Home', '/', array('link_order' => -1000));
$navigation->addLink('About Me', '/about-me', array('link_order' => 2));
$navArray = [
[
'title' => 'My Link',
'uri' => '/my-link-page',
'link_order' => 3
],
[
'title' => 'Has Children',
'uri' => '/child/',
'link_order' => 4
'children' => [
[
'title' => 'Second Child',
'uri' => '/child/second',
'link_order' => 2
],
[
'title' => 'First Child',
'uri' => '/child/first',
'link_order' => 1
],
[
'title' => 'Last Child',
'uri' => '/child/last',
'link_order' => 3
],
]
]
];
$navigation->addLinks($navArray);
The addLink method allows the following:
$navigation->addLink($title, $uri [, $options = []]);
$title Is a string that should contain the test to display on the link
$uri Is a string that should contain the link URI
$options Is an array that can contain any of the following array elements ['label', 'uri', 'fragment', 'title', 'target', 'rel', 'class', 'id', 'link_order', 'active', 'li_class', 'li_id', 'ul_class', 'ul_id', 'children']
Set Current URI
Set the active link for the menu
$navigation->setCurrentURI('/about-me');
Output the menu to the screen
echo($navigation->render());
Output a breadcrumb menu to the screen
echo($navigation->renderBreadcrumb());