如何在 Yii 中添加 HTML CMenu


how to add HTML CMenu in yii

希望你们都过得好。我一直在尝试在 Yii 模板中实现 CMenu。我正在使用,

$this->widget('zii.widgets.CMenu', array(
            'items'=>$this->menu,
            'htmlOptions'=>array('class'=>'collapse','id'=>'component-nav'),
));

我想将我的 HTML 输出作为

<li class=""><a href="icon.html"><i class="icon-angle-right"></i> List Registration </a></li>

但我不能插入本节:<i class="icon-angle-right"></i>标签旁边,即"列表注册"。有没有办法在项目的每个标签旁边插入这个<i class="icon-angle-right"></i> html部分。

请帮帮我一个人。

提前致谢

一种快速的肮脏方式:

$this->menu = array_map(function($item){
        $item["label"] = "<i class='icon-angle-right'></i>" . $item["label"];
        $item["encodeLabel"] = false;
        return $item;
}, $this->menu);
$this->widget('zii.widgets.CMenu', array(
            'items'=>$this->menu,
            'htmlOptions'=>array('class'=>'collapse','id'=>'component-nav'),
));

来自 http://www.yiiframework.com/wiki/525/customizing-the-cmenu-widget/的信息

  1. 禁用 HTML 编码'encodeLabel' => false,
  2. 子菜单更改类'submenuHtmlOptions' => array('class' => 'dropdown-menu',)
  3. 使用标签属性 'label' => '<i class="icon-user"></i><span class="username">Admin</span> <i class="icon-angle-down"></i>', 对引导非常有用
  4. 使用 YII url 属性进行正确的地址,即 'url' => array('site/logout'),

我不认为 Yii 提供了一种根据类引用 (yiiframework.com/doc/api/1.1/CMenu) 在 a 中添加 html 元素的方法。如果你想用css的方式做:

#component-nav li a { 
     background: url('path/to/image.png') no-repeat; 
     padding-left: 30px; // depends of the width of your image 
}