perochak
(Amjad Mughal)
November 30, 2010, 6:46am
1
Hi dears,
I am using the SMenu for the menu of my application.
I want to make the top menu active if the sub menu item is being active.
I.e.
if in the menu list there are
Main ->
sub 1
sub 2
and if the user is on the page sub 2
then the top menu Main should be set active.
Please help me in it.
Thanks
perochak
(Amjad Mughal)
December 1, 2010, 8:53am
2
I have done it using CMenu.
I modified the CMenu such that it fits in the required domain.
Thanks
fouss
(Jsfousseni)
December 13, 2010, 12:58pm
3
Could you please explain how you did that?
perochak
(Amjad Mughal)
December 15, 2010, 9:59am
4
We can have it using the Active property of the Cmenu
If we have a items in our sub menu which belongs to the different controllers then we can use a custom code as fellow to have our top menu item active
$sub_menu_controllers=array('site','site2','site3');
$sub_menu_active='false';
if(in_array(Yii::app()->controller->id,$sub_menu_controllers)){
$sub_menu_active='true';
}
Now in your CMenu widget, we can have
$this->widget('zii.widgets.CMenu', array(
'items'=>array(
array('label'=>'Title','URL'=>'','active'=>$sub_menu_active),
);
This is just a trick to get what I want.
It could be Improved.
Hopefully, will help someone.
Thanks
roshchyn
(Oleksiy)
January 10, 2014, 10:10am
5
Hi All,
As described here http://www.yiiframework.com/doc/api/1.1/CMenu#activateParents-detail
normally, to make parent menu item active (by ‘active’ i mean that when you are on example.com/page/6 , Page in main menu should be also with class=‘active’)
it is enough to simply pass parameter ‘activateParents’=>‘true’ in a CMenu widget
But it is still not working.
Does anyone know where the problem is?
Thanks in advance,