简体   繁体   中英

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?

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')
));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM