0

I am using kartik SideNav widget in my project. I want the menu active and open when I click on it but it not works.Actually I dont know about $item and $type variables that how to use in the sidenav. thanx in advance for solving it.

my code is below.

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

],

]);

1 Answer 1

0

$item is id of your action, like actionCreate will output here create.

Add here:

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

Which will output products for ProductsController.

In option active use:

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

And you should rename $item to $actionId or something similiar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.