1、首先引入类
use yii\widgets\Menu;
2、配置组件
<?php echo Menu::widget([ //ul的样式以及相应的属性 'options' => ['class' => 'nav nav-pills nav-stacked custom-nav'], //设置子级目录li的样式结构 'submenuTemplate' => '<ul class="sub-menu-list">{items}</ul>', //是否允许解析label里面的html,方便添加小图标 'encodeLabels' => false, //父节点是否根据动态路由进行高亮显示,注意url必需要以数组的形式进行固定 'activateParents' => true, //设置动态时候添加的css类 'activeCssClass' => 'active', //子级目录 'items' => [ [
//注意会自动生成a标签 'label' => '<i class="fa fa-laptop"></i><span>上传下载</span>', 'url' => ['javascript:;'], 'options' => ['class' => 'menu-list'], 'items' => [ ['label' => '表格操作', 'url' => ['/default/index']], ['label' => '上传图片', 'url' => ['/upload/index']] ] ], [ 'label' => '<i class="fa fa-book"></i><span>小部件应用</span>', 'url' => 'javascript:;', 'options' => ['class' => 'menu-list'], 'items' => [ ['label' => '部件一', 'url' => ['/widget/index']], ['label' => '部件二', 'url' => ['/widget/set']] ] ], ['label' => '<i class="fa fa-book"></i><span>小部件应用</span>', 'url' => ['default/index']] ] ]) ?>