我正在创建一个基于 yii2 和 learn-plus 仪表板主题的 Web 应用程序,可折叠侧边栏导航菜单已经实现,其 id 充当目标链接 (#menu_id),以便在单击父链接时打开菜单,现在我我正在尝试使用 Multiple submenuTemplate 添加 Yii2 Menu::widget,以便我可以容纳这些 ID,因为每个子菜单都应该有自己的 ID。
我已经创建了菜单,它与单个可折叠菜单完美配合,当我添加菜单的多个可折叠部分时,问题就出现了。
<?php
use yii\widgets\Menu;
use yii\helpers\Html;
/**
* Created by PhpStorm.
* User: Mr Daud Mabena
* Date: 01/05/19
* Time: 01:34 PM
*/
echo Menu::widget([
'activeCssClass' => "active",
'activateParents' => true,
'encodeLabels' => false,
'submenuTemplate' => "\n<ul class='sidebar-submenu sm-indent collapse' id='setup_menu'>\n{items}\n</ul>\n",
'options' => ['class' => 'sidebar-menu'],
'items' => [
[
'label' => 'Security Dashboard',
'url' => ['/security/'],
'options' => ['class' => 'sidebar-menu-item'],
'template' => "<a class='sidebar-menu-button' href='{url}'>
<i class='sidebar-menu-icon sidebar-menu-icon--left material-icons'>bar_chart</i>
{label}
</a>",
],
[
'id' => 'components_menu',
'template' => "<a class='sidebar-menu-button sidebar-js-collapse' data-toggle='collapse' href='#setup_menu'>
<i class='sidebar-menu-icon sidebar-menu-icon--left material-icons'>tune</i>
List of Users
<span class='ml-auto sidebar-menu-toggle-icon'></span>
</a>",
'items' => [
[
'label' => 'Staffs',
'url' => ['/security/users/staffs'],
'template' => "<a class='sidebar-menu-button' href='{url}'><span class=\"sidebar-menu-text\">{label}</span></a>",
'options' => ['class' => 'sidebar-menu-item'],
],
[
'label' => 'Applicant',
'url' => ['/security/users/applicants'],
'template' => "<a class='sidebar-menu-button' href='{url}'><span class=\"sidebar-menu-text\">{label}</span></a>",
'options' => ['class' => 'sidebar-menu-item'],
],
[
'label' => 'Students',
'url' => ['/security/users/students'],
'template' => "<a class='sidebar-menu-button' href='{url}'><span class=\"sidebar-menu-text\">{label}</span></a>",
'options' => ['class' => 'sidebar-menu-item'],
],
]
],
[
"label" => "Add New Staff",
"url" => ["/security/users/create"],
"template" => "<a class='sidebar-menu-button' href='{url}'><i class='fa fa-bar-chart' aria-hidden='true'></i> {label}</a>",
],
[
"label" => "Logout",
"url" => ["/admission/applicants/reports"],
"template" => Html::beginForm(['/security/users/logout'], 'post') . Html::submitButton('Logout', ['class' => 'sidebar-menu-button logout']) . Html::endForm(),
],
],
]);
我需要有多个
'submenuTemplate' => "\n<ul class='sidebar-submenu sm-indent collapse' id='setup_menu'>\n{items}\n</ul>\n",
具有不同的 id,第一个是 setup_menu 希望添加其他 id,如 access_levels 等