PHP code example of tlr / menu

1. Go to this page and download the library: Download tlr/menu library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tlr / menu example snippets


$menu = new Tlr\Menu\MenuItem;

$home = $menu->item( 'home', 'Home', 'http://foo.com' );
$blog = $menu->item( 'blog', 'Blog', 'http://foo.com/blog' );
$about = $menu->item( 'about', 'About', 'http://foo.com/about-us' );

$about->item( 'where-we-are', 'Where We Are', 'http://eric.com/where-are-we' );
$about->item( 'contact-us', 'Contact Us', 'http://eric.com/contact-us' );

$blog = $menu->item('blog');

$repo = new MenuRepository;

$headerMenu = $repo->menu( 'header-nav' );
$footerMenu = $repo->menu( 'footer-nav' );

$headerMenu = $repo->menu( 'header-nav' ); // will use the existing menu instance cached with this key
$newMenu = $repo->menu( 'other-nav' ); // that key hasn't been used yet, so a new instance will be created and cached with that key

// This will filter the items based on user permissions
$menu->getItems(function($item) use ($user)
{
	return $user->can( $item->option( 'permissions', array() ) );
});

// This will add a filter that only lets the given user see the menu items if they have the appropriate auth level
$menu->addFilter(function($item) use ($user)
{
	return $item->option('auth') <= $user->authLevel;
});
$menu->getItems();

$about->addFilter(function()
{
	return $item->isVisible();
});

$menu->addFilter(function($item) use ($user)
{
	return $user->canSeePage( $item );
}, false);

$home = $menu->item( 'home', 'Home', 'http://foo.com' );
$blog = $menu->item( 'blog', 'Blog', 'http://foo.com/blog' );
$about = $menu->item( 'about', 'About', 'http://foo.com/about-us' );
    $contact = $about->item( 'contact', 'Contact Us', 'http://foo.com/contact-us' );
    $find = $about->item( 'find', 'Find Us', 'http://foo.com/find-us' );

$blog->setActive();

$menu->activate( $currentUrl );

$home = $menu->item( 'home', 'Home', [ 'link' => 'http://foo.com', 'routename' => 'home' ] );
$blog = $menu->item( 'blog', 'Blog', [ 'link' => 'http://foo.com/blog', 'routename' => 'blog' ] );

$menu->activate( 'blog', 'routename' );

$menu = Menu::menu( 'nav' );
$menu->item('Home')

$menu->setView( 'my.menu.view' );

$menu->item( $key[, $title = "", $options = array(), $attributes = array(), $index = $n + 100] )