0

我在我的项目中使用 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')],
    ]],

],

]);

4

1 回答 1

0

$item是您的操作的 id,就像actionCreate将在此处输出一样create

在此处添加:

$controllerId = Yii::$app->controller->id;

这将输出products.ProductsController

在选项active使用中:

'active' => $controller == 'products' && $item == 'create'

你应该重命名$item$actionId或类似的东西。

于 2017-01-31T06:51:50.980 回答