I'm newbie to yii and I want to know:
How to apply individual classes(CSS) for zii.widgets.CMenu labels?
My code:
$this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'Home',
'url'=>array('/site/index')),<br>
array('label'=>'About',
'url'=>array('/site/page', 'view'=>'about')),<br>
array('label'=>'Contact',
'url'=>array('/site/contact')),<br>
array('label'=>'Supplier',
'url'=>array('/supplier/index')),<br>
array('label'=>'Login',
'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout
('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), <br>
'visible'=>!Yii::app()->user->isGuest)
),<br>
));
You can supply itemOptions according to the official documentation that can be found here.
itemOptions, according to the documentation, are "Additional HTML attributes to be rendered for the container tag of the menu item."
This means they can be used to add HTML attributes to your items, as well as li
elements like so:
$this->widget('zii.widgets.CMenu', array
(
'items' => array
(
array
(
'itemOptions' => array('class' => 'class names here'),
'label' => 'Home',
'url' => array('/site/index')),
),
),
));
Alternatively you can use linkOptions to add classes to the a href
elements themselfs like so (note the change from itemOptions to linkOptions)
$this->widget('zii.widgets.CMenu', array
(
'items' => array
(
array
(
'linkOptions' => array('class' => 'class names here'),
'label' => 'Home',
'url' => array('/site/index')),
),
),
));
For li
use itemOptions
and for a href
use linkOptions
For a href
array('label'=>'Link Lable',
'url'=>array('controller/action'),
'linkOptions'=>array("id"=>"link-id","class"=>"your-class1 your-class2 your-class3"),
'visible'=>!Yii::app()->user->isGuest)
For li
'itemOptions' => array('class' => 'your-class1 your-class2'),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With