Search code examples
phpyiicmenu

How can I assign a class to the unordered list created by Menu Widget in Yii?


When using Yii, I am creating a menu using the CMenu widget:

$this->widget('zii.widgets.CMenu',array(
  'items'=>array(
      array('label'=>'Home', 'url'=>array('/site/index')),
      array('label'=>'Contact', 'url'=>array('/site/contact')),
  ),
));

This will output the following html:

<ul id="yw0">
  <li class="active"><a href="/site/index">Home</a></li>
  <li><a href="/site/contact">Contact</a></li>
</ul>

I am trying to add a class to the unordered list. How can I do that?


Solution

  • Use this -

    $this->widget('zii.widgets.CMenu',array(
      'items'=>array(
          array('label'=>'Home', 'url'=>array('/site/index')),
          array('label'=>'Contact', 'url'=>array('/site/contact')),
      ),
     'htmlOptions' => array('class' => 'blah')
    ));