Yii 1.1: How To add id or class to CMenu items ?

CMenu comes with a lot of great customization options built in. One of the most used is the class 'active' being added to menu item. But, what if you want to add your own class or id to a menu item ?

It's very easy, you just need to use the 'itemOptions'.

If you want a menu like :

<ul id="myMenu">
            <li  id="first"><a href="#"><span>First</span></a></li>
            <li id="second"><a href="#"><span>Second</span></a></li>
</ul>

Just do :

<?php $this->widget('application.components.MyMenu', array(
    'id' => 'myMenu',
    'items' => array(
       array('label' => 'First', 'url' => array('#'), 'itemOptions'=>array('id' => 'first'), ),
       array('label' => 'First', 'url' => array('#'), 'itemOptions'=>array('id' => 'second'), ),
    ),
));
?>

That's all folks !