Yii Framework Forum: CMenu - Yii Framework Forum

Jump to content

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

CMenu Rate Topic: -----

#1 User is offline   tuga 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 02-January 10

Posted 24 March 2010 - 01:11 PM

Hi all,
I'm using CMenu widget on my layout, and I need to set the active property manually.
I've changed the urls with urlmanager so it will not match and will not be active.
For instance my url is http://rochat.lan/fa...raia+da+Rocha/5 but my menu item is
array(
								'label' => 'SERVICES ', 
								'url' => array(
									'/services/index')
								), 

So I thinks this will never match, is there any way of setting manually the active property??

Thanks
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,346
  • Joined: 17-January 09
  • Location:Russia

Posted 24 March 2010 - 02:17 PM

It should match this way.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   tuga 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 02-January 10

Posted 24 March 2010 - 07:54 PM

View Postsamdark, on 24 March 2010 - 02:17 PM, said:

It should match this way.


Hi samdark,
But I could not understand, why you say it should match.
My url is h**p://rochat.lan/faro/airport/transfer/Praia+da+Rocha/5 and my item in the CMenu widget is
'url'=>array('services/index')


Could you please be more specific

Thanks
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,346
  • Joined: 17-January 09
  • Location:Russia

Posted 24 March 2010 - 08:56 PM

If h**p://rochat.lan/faro/airport/transfer/Praia+da+Rocha/5 actually leads to 'services/index' route, it will match.

If you want to do it manually:
array(
  'label' => 'SERVICES ', 
  'url' => array('/services/index'),
  'active' => true,
)


Another option is to implement your own logic by overriding http://www.yiiframew...mActive-detail.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 24 March 2010 - 09:44 PM

array(
    array(
        'label' => 'SERVICES ', 
        'url' => array('/services/index'),
    ),
)

0

#6 User is offline   tuga 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 02-January 10

Posted 25 March 2010 - 04:11 AM

View Postsamdark, on 24 March 2010 - 08:56 PM, said:

If h**p://rochat.lan/faro/airport/transfer/Praia+da+Rocha/5 actually leads to 'services/index' route, it will match.

If you want to do it manually:
array(
  'label' => 'SERVICES ', 
  'url' => array('/services/index'),
  'active' => true,
)


Another option is to implement your own logic by overriding http://www.yiiframew...mActive-detail.


Thank you samdark, you were right actually one didn't lead to the other (my mistake). The controllers are actually different.

But I think I cannot do it manually as the widget is on the layout, so the active property has to change, I cannot set it to true, because will be always active.

I think I don't understand quite well the CMenu class.

I did find a solution, maybe not the correct but it works:
In the controller I created a property and then on the action I will tell which menu item I should highlight
class MyController extends Controller{
protected $menuActive;

public function actionIndex(){
$this->menuActive = '/services/index';
} 
}


Then on the layout I did
$this->widget('application.components.CMenu', array(
						'id' => 'mainmenu', 
						'items' => array(
							
							array(
								'label' => 'ABOUT US ', 
								'url' => array(
									'/site/about')), 
							array(
								'label' => 'SERVICES ', 
								'url' => array(
									'/services/index'), 
								'active' => $this->menuActive == '/services/index' ? true : null
								), 
							array(
								'label' => 'RESERVATIONS ', 
								'url' => array(
									'/site/reservations')), 
							array(
								'label' => 'CONTACTS', 
								'url' => array(
									'/site/contacts')))));


Thank you all for your help.
0

#7 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 25 March 2010 - 04:58 AM

tuga, your solution works, but maybe you can try even like that:

'active' => (($this->id=='services') && ($this->action->id=='index'))



In the view template the $this is always the controller, and so in id and action you have teh current controller name and action.

That's allows you to avoid you to extend controller, and you can put all active checks of menu in the menu itself
0

#8 User is offline   tuga 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 02-January 10

Posted 25 March 2010 - 06:56 AM

View Postzaccaria, on 25 March 2010 - 04:58 AM, said:

tuga, your solution works, but maybe you can try even like that:

'active' => (($this->id=='services') && ($this->action->id=='index'))



In the view template the $this is always the controller, and so in id and action you have teh current controller name and action.

That's allows you to avoid you to extend controller, and you can put all active checks of menu in the menu itself


Thank you zaccaria for your help, but that actually wouldn't work as the controller is another. In your solution even normal match would occur.

Thanks anyway.
0

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