Create a HTML menu and breadcrumb menu items from a PHP array, (*1)
Installation
Installation is available via Composer/Packagist:, (*2)
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., (*3)
Basic Usage
Make a new instance of the Navigation
menu builder, (*4)
<?php
$navigation = new Menu\Navigation();
Add some menu items, (*5)
// Add links individually
$navigation->addLink('Home', '/', array('link_order' => -1000));
$navigation->addLink('About Me', '/about-me', array('link_order' => 2));
// Add an array of links
$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:, (*6)
$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, (*7)
$navigation->setCurrentURI('/about-me'); // Makes the about me page the current select item in the menu
Output the menu to the screen, (*8)
echo($navigation->render());
Output a breadcrumb menu to the screen, (*9)
echo($navigation->renderBreadcrumb());