PHP code example of itstructure / yii2-multi-level-menu
1. Go to this page and download the library: Download itstructure/yii2-multi-level-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/ */
itstructure / yii2-multi-level-menu example snippets
use Itstructure\MultiLevelMenu\MenuWidget;
echo MenuWidget::widget([
'menuId' => 'multi-level-menu',
'data' => array_values($dataProvider->getModels()),
'itemTemplate' => '@app/views/MultiLevelMenu/main.php'
]);
use yii\helpers\{Url, Html};
/* @var app\models\Page $data */
<span>
echo Html::a(
Html::encode($data->title),
Url::to(['view', 'id' => $data->id])
)
use Itstructure\MultiLevelMenu\MenuWidget;
echo MenuWidget::widget([
'menuId' => 'multi-level-menu',
'data' => array_values($dataProvider->getModels()),
'itemTemplate' => '@app/views/MultiLevelMenu/main.php'
'mainContainerOptions' => [
'class' => 'list-group'
],
'itemContainerOptions' => [
'levels' => [
['class' => 'list-group-item'],
['class' => 'list-group-item list-group-item-success'],
['class' => 'list-group-item list-group-item-warning'],
]
],
]);
use Itstructure\MultiLevelMenu\MenuWidget;
echo MenuWidget::widget([
'menuId' => 'multi-level-menu',
'data' => array_values($dataProvider->getModels()),
'itemTemplate' => '@app/views/MultiLevelMenu/main.php'
'mainContainerOptions' => function () {
return [
'class' => $level == 0 ? 'nav navbar-nav navbar-right' : 'dropdown-menu'
];
},
'itemTemplateParams' => function ($level, $item) {
return [
'linkOptions' => isset($item['items']) && count($item['items']) > 0 ? [
'class' => 'dropdown-toggle',
'data-toggle' => 'dropdown',
'aria-haspopup' => 'true',
'aria-expanded' => 'false',
] : [],
];
},
'itemContainerOptions' => function ($level, $item) {
return $level == 0 ? [
'class' => isset($item['items']) && count($item['items']) > 0 ? 'nav-item dropdown' : 'nav-item'
] : [
'class' => isset($item['items']) && count($item['items']) > 0 ? 'dropdown-item dropdown' : 'dropdown-item'
];
}
]);