我在我的项目中使用 kartik SideNav 小部件。我希望菜单处于活动状态并在单击时打开,但它不起作用。实际上我不知道如何在 sidenav 中使用的 $item 和 $type 变量。提前thanx解决它。
我的代码如下。
$type = SideNav::TYPE_PRIMARY;
$item = Yii::$app->controller->action->id;
echo SideNav::widget([
'type' => $type,
'encodeLabels' => false,
'items' => [
['label' => 'Home', 'icon' => 'home', 'url' => Url::to(['/site/index']), 'active' => ($item == 'index')],
['label' => '<span class="pull-right badge">2</span> Products', 'icon' => 'book', 'items' => [
['label' => '<span class="pull-right badge"></span> Products', 'url' => Url::to(['/products']), 'active' => ($item == 'http://localhost/test_project_yii2/backend/web/products')],
['label' => '<span class="pull-right badge"></span> Add Product', 'url' => Url::to(['/products/create']), 'active' => ($item == '/products/create')],
]],
],
]);