PHP code example of andrewdanilov / yii2-menu

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

    

andrewdanilov / yii2-menu example snippets


<?= andrewdanilov\menu\Menu::widget([
    'templateWrapper' => '@frontend/views/site/_blocks/menu/wrapper',
    'templateParentItem' => '@frontend/views/site/_blocks/menu/parent-item',
    'templateItem' => '@frontend/views/site/_blocks/menu/item',
    'templateActiveItem' => '@frontend/views/site/_blocks/menu/active-item',
    'wrapperId' => 'my_menu', // optional, default is 'menu'
    'items' => [
        [
            'label' => 'Menu item 1', // ], // optional for items has submenu
            'items' => [
                ['label' => 'Menu subitem 3', 'url' => ['site/action4']],
                ['label' => 'Menu subitem 4', 'url' => ['site/action5']],
            ],
        ],
        [
            'label' => 'Menu item 3',
            'url' => ['site/action6'],
            'target' => '_blank',
        ],
    ],
]) 

<?= andrewdanilov\menu\MobileMenu::widget([
    'templateWrapper' => '@frontend/views/site/_blocks/mobile-menu/wrapper',
    'templateParentItem' => '@frontend/views/site/_blocks/mobile-menu/parent-item',
    'templateItem' => '@frontend/views/site/_blocks/mobile-menu/item',
    'templateActiveItem' => '@frontend/views/site/_blocks/mobile-menu/active-item',
    'templateButton' => '@frontend/views/site/_blocks/mobile-menu/button',
    'buttonLabel' => 'Menu', // optional, default is ''
    'wrapperId' => 'my_mobile_menu', // optional, default is 'mobile_menu'
    'showNavbar' => true, // optional, default is false
    'items' => [
        [
            'label' => 'Menu item 1',
            'items' => [
                ['label' => 'Menu subitem 1', 'url' => ['site/action1'], 'target' => '_blank'],
                ['label' => 'Menu subitem 2', 'url' => ['site/action2']],
            ],
        ],
        [
            'label' => 'Menu item 2',
            'items' => [
                ['label' => 'Menu subitem 3', 'url' => ['site/action3']],
                ['label' => 'Menu subitem 4', 'url' => ['site/action4']],
            ],
        ],
        ['label' => 'Menu item 3', 'url' => ['site/action3'], 'target' => '_blank'],
        ['label' => 'Menu item 4', 'url' => ['site/action4']],
    ],
])