PHP code example of nurmanhabib / navigator

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

    

nurmanhabib / navigator example snippets


use Nurmanhabib\Navigator\NavCollection;
use Nurmanhabib\Navigator\Navigator;

$menu = new NavCollection;
$menu->addHome();
$menu->addLink('Berita', '/berita')->match('berita*');
$menu->addSeparator();
$menu->addParent('Kategori', function (NavCollection $menu) {
    $menu->addLink('Teknologi', '/kategori/teknologi');
    $menu->addLink('Otomotif', '/kategori/otomotif');
    $menu->addParent('Lifestyle', function (NavCollection $menu) {
        $menu->addLink('Pria', '/lifestyle-pria');
        $menu->addLink('Wanita', '/lifestyle-wanita');
    });
});

$menu->addHeading('Configuration');
$menu->addLink('Application', '/config/app');

$menu->addHeading('Account');
$menu->addLink('My Profile', '/profile');
$menu->addLink('Logout', '/logout');

$navigator = new Navigator($menu);

echo $navigator->render();

$data = [
    [
        'text' => 'Home',
        'url' => '/'
    ],
    [
        'text' => 'Berita',
        'url' => 'berita',
        'match' => '/berita*'
    ],
    [
        'type' => 'separator'
    ],
    [
        'text' => 'Kategori',
        'child' => [
            [
                'text' => 'Teknologi',
                'url' => 'kategori/teknologi'
            ],
            [
                'text' => 'Otomotif',
                'url' => 'kategori/otomotif'
            ],
            [
                'text' => 'Lifestyle',
                'child' => [
                    [
                        'text' => 'Pria',
                        'url' => 'lifestyle-pria'
                    ],
                    [
                        'text' => 'Wanita',
                        'url' => 'lifestyle-wanita'
                    ],
                ]
            ],
        ]
    ],
    [
        'type' => 'heading',
        'text' => 'Configuration'
    ],
    [
        'text' => 'Account',
        'child' => [
            [
                'text' => 'Change Password',
                'url' => 'change-password'
            ],
            [
                'text' => 'Logout',
                'url' => 'logout'
            ],
        ]
    ],
];

$factory = new ArrayNavCollectionFactory($data);

$menu = $factory->createNavCollection();

$navigator = new Navigator($menu);

echo $navigator->render();

    $menu->addLink('Teknologi', 'kategori/teknologi')->match('kategori/*');
    

    $menu->addLink('Teknologi', 'kategori/teknologi')->setData(['key' => 'value']);
    

    $item->hasData('key');
    

    echo $item->getData('key');
    

    echo $item->getType();