PHP code example of nethead / menu

1. Go to this page and download the library: Download nethead/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/ */

    

nethead / menu example snippets


use Nethead\Menu\Factories\MenusFactory;

MenusFactory::make('main-menu');

use Nethead\Menu\Activators\BasicUrlActivator;
use Nethead\Menu\Renderers\MarkupRenderer;
use Nethead\Menu\Repository;
use Nethead\Menu\Menu;

$menu = new Menu('sidebar', new BasicUrlActivator(), new MarkupRenderer());

Repository::set($menu);

use Nethead\Menu\Repository;

// one created with MenusFactory
$mainMenu    = Repository::get('main-menu');
// one created manually and registered
$sidebarMenu = Repository::get('sidebar');   

use Nethead\Menu\Activators\BasicUrlActivator;
use Nethead\Menu\Renderers\MarkupRenderer;
use Nethead\Menu\Items\Internal;
use Nethead\Menu\Menu;

$menu = new Menu('sidebar', new BasicUrlActivator(), new MarkupRenderer());
$item = new Internal(['The text for the link'], '/one/of/your/pages', $menu);
$menu->setItem($item);

use Nethead\Menu\Factories\MenusFactory;
use Nethead\Menu\Factories\ItemsFactory;

MenusFactory::make('main-menu', function(ItemsFactory $factory) {
    $factory->internal(['Homepage'], '/');
    $factory->external(['Example domain'], 'http://example.com');
    
    $factory->simple(['Table of contents'])->group(function(ItemsFactory $factory) {
        $factory->anchor(['Chapter 1'], 'chapter-1');
        $factory->anchor(['Chapter 2'], 'chapter-2');
        $factory->anchor(['Chapter 3'], 'chapter-3');
    });
    
    $factory->simple(['Contact'])->group(function(ItemsFactory $factory) {
        $factory->special(['Mail me'], 'mailto', '[email protected]');
        $factory->separator();
        $factory->special(['Call me'], 'tel', '555555555');
    });
});