Yii Framework Forum: menu widget, active class not added - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

menu widget, active class not added Rate Topic: -----

#1 User is offline   wisp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 192
  • Joined: 04-February 11

Posted 15 May 2012 - 04:51 PM

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
0

#2 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 488
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 17 May 2012 - 08:04 AM

View Postwisp, on 15 May 2012 - 04:51 PM, said:

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...
0

#3 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 492
  • Joined: 21-May 11
  • Location:India

Posted 06 December 2012 - 04:07 AM

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..


View Postwisp, on 15 May 2012 - 04:51 PM, said:

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

Thanks,
Kiran Sharma.
2

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users