Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Nav widget : active item

Tags:

nav

yii2

I have Nav with items:

[
    'label' => 'All',
    'url' => ['project/index'],
],
[
    'label' => 'Done',
    'url' => ['project/index', 'assigned' => 'done'],
],

But both of them have an active class when I go to project/index&assigned=done. How can I force to attach this class only if item's url is strictly equal to $route value?

like image 785
Dmytro Avatar asked May 04 '16 11:05

Dmytro


1 Answers

Nav widget will make an item active when its route and parameters match $route (if not set, it will use the route of the current request) and $params (if not set, it will use $_GET).

Your first item will always be active if the route is project/index (take a look here).

You should try this for example :

[
    'label' => 'All',
    'url' => ['project/index', 'assigned' => 'not-done'],
],
[
    'label' => 'Done',
    'url' => ['project/index', 'assigned' => 'done'],
],

Read more about how Nav widget set an item active or not.

like image 134
soju Avatar answered Oct 17 '22 09:10

soju