"selected" links in "Cmenu"

Hi,

I’m using the zii.widgets.CMenu to display my side menu (which is generated using Gii). I want to “select” or “highlight” the menu item when I visit that. have tried passing “aciveCSSClass” but it does not work.

  • The class get passe to the “CMenu” class but some it is checking for some preoperty called “$item[‘active’]” in the “renderMenuRecursive” function which dons not have a value and because of that the class does not get passed to the front end.
  1. What is the stranded code for using the "aciveCSSClass" ?

  2. Do I have to pass another parameter to use the "selected" links?

Below is the code I’m using currently.




$this->beginWidget('zii.widgets.CMenu', 

		array(

			'items'=>$this->menu,

			'htmlOptions'=>array('class'=>'operations'),

			'activeCssClass'=>array ('selected'),// This get passe but the links do not work

		));

		

		$this->endWidget();




any help is much appreciated.

Thanks

Hi!

certainly I don’t know how to use the ‘activeCssClass’ too … so, I’ve tried to other way to select the active menu

What happend when I select a menu (or category) and this has a lot of views (inside this category)??

for example I have a menu

| Animals | Fruits | …

and inside this items

Animals: dog view, cat view, horse view, etc (Animals menu is always selected)

Fruits: banana view, apple view, etc (Fruits menu is always selected)

main view (layouts)




<div id="mainmenu">

                <?php                   

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

                            'id' => "menu",

                            'items' => array(

                                array('label' => 'Animals', 'url' => array('/animals/index'), 'active' => yii::app()->user->getState('mnuSelected') == 'mnuAnimals' ? true : false),

                                array('label' => 'Fruits', 'url' => array('/fruits/index'), 'active' => yii::app()->user->getState('mnuSelected') == 'mnuFruits' ? true : false),

                            ),

                        ));

                ?>

            </div>



animals view


 public function actionIndex() {


       ...


        yii::app()->user->setState('mnuSelected','mnuAnimals');

...




        $this->render('admin', array(

            'model' => $model,

        ));

    }



fruits view


 public function actionIndex() {


       ...


        yii::app()->user->setState('mnuSelected','mnuFruits');

...




        $this->render('admin', array(

            'model' => $model,

        ));

    }



I hope this can help you … Is there another ‘best’ way to do this?? :unsure:

Thanks ClaCS…!

Thank you for helping.

Actually I have found a better way of doing this.

main.php code (layout file)

Note that I’m passing ‘activeCssClass’=>‘selected’,

You can define ‘selected’ class in your css file.




$this->beginWidget('application.customextentions.UserMenu', 

		array(

			'items'=>$this->menu,

			'htmlOptions'=>array('class'=>'operations'),

			'activeCssClass'=>'selected',

		));

		

		$this->endWidget();



Then my view would look like this




$this->menu=array(

	array('label'=>'Create Adminuser', 'url'=>array('create'),'active'=>($this->action->Id == 'create' ? true: false)),

	array('label'=>'Manage Adminuser', 'url'=>array('admin'),'active'=>($this->action->Id == 'admin' ? true: false)),

	array('label'=>'List Adminuser', 'url'=>array('index'),'active'=>($this->action->Id == 'index' ? true: false)),


);



Hope this will help