menu widget, active class not added

When I use the CMenu widget, there should by a class added to the list item when it is active (the property $activeCssClass is ‘active’ by default). This works fine, until I use URL rules to make the links SEO friendly.

Is this a bug or am I doing something wrong?

I’m using Yii 1.1.10 r3566

My code:


  <? $this->widget('zii.widgets.CMenu', array(

            'items' => array(

                array('label' => 'Home', 'url' => array('/site')),

                array('label' => 'Products', 'url' => $this->createUrl('/catalog/product')),

                array('label' => 'References', 'url' => array('/site/references')), #works!

                array('label' => 'Offer', 'url' => array('/site/offer')), #works!

                array('label' => 'Contact', 'url' => array('/site/contact')),

            ),

        )); ?>

-edit- I think the problem is that using $this->createUrl() inside the menu widget is causing it to fail

So why do you do it?

CMenu runs createUrl itself when you provide an array and I guess it needs that to detect if item is active or not.

You do not need the createUrl here…

Yes the problem is to find specific url…

The reported problem is occure when we use module and use url.

suppose i have module user and i had login action in login controller, so i can do below thing form menu as how menu item gets active defined below.

In both cases it will redirect to login page in user module…




array('label'=>Yii::t('frontend','Login'), 'url'=>array('/user/login/login'), 'visible'=>Yii::app()->user->isGuest), // Working, Login tag activated on login page


array('label'=>Yii::t('frontend','Login'), 'url'=>array('/user/login'), 'visible'=>Yii::app()->user->isGuest), // Not working, Login tag not activated on login page

So, we can have problem to beautify url…