【问题标题】:Using kartik SideNav widget in yii2在 yii2 中使用 kartik SideNav 小部件
【发布时间】:2017-01-31 14:51:50
【问题描述】:

我在我的项目中使用了 kartik SideNav 小部件。我希望菜单在单击时处于活动状态并打开,但它不起作用。实际上,我不知道如何在 sidenav 中使用的 $item 和 $type 变量。感谢您提前解决它。

我的代码如下。

$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')],
    ]],

],

]);

【问题讨论】:

    标签: yii2-advanced-app kartik-v


    【解决方案1】:

    $item 是您的操作的 id,例如 actionCreate 将在此处输出 create

    在此处添加:

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

    将为ProductsController 输出products

    在选项active 中使用:

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

    您应该将 $item 重命名为 $actionId 或类似名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多