如何在Yii CMenu标签中添加原始HTML

前端之家收集整理的这篇文章主要介绍了如何在Yii CMenu标签中添加原始HTML前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建一个菜单,如一个带有CMenu小部件的Twitter Bootstrap导航栏:
<?PHP 
    $this->widget( 'zii.widgets.CMenu',array(
    'items' => array(
        array(
            'label' => 'Home','url' => array( '/site/index' ),),array( 
            'label' => 'Dropdown <b class="caret"></b>','url' => '#','submenuOptions' => array( 'class' => 'dropdown-menu' ),'items' => array( 
                array( 
                    'label' => 'Submenu Item 1','url' => array( '/user/create' ),array( 
                    'label' => 'Submenu Item 1','url' => array( '/user/list' ),'itemOptions' => array( 'class' => 'dropdown' ),'linkOptions' => array( 'class' => 'dropdown-toggle','data-toggle' => 'dropdown' ),'htmlOptions' => array( 'class' => 'nav' ),)); ?>

代码生成菜单,其中有2个项目,第二个菜单项有1个子菜单.精细.但只有事情不起作用就是’label’=> ‘dropdown< b class =“caret”>< / b>‘,在第9行.它呈现为Dropdown& lt; b class =& quot; caret& quot;& gt;& lt; / b& gt;在页面上所以我看到标题’Dropdown< b class =“caret”>< / b>‘而不是下拉▼.

如何更改代码以在菜单标签显示未转义的HTML?

感谢您的关注.

您必须将 CMenuencodeLabel属性设置为false
<?PHP
$this->widget('zii.widgets.CMenu',array(
    'encodeLabel' => false,'htmlOptions' => array('class' => 'nav'),'items' => array(
        array(
            'label' => 'Home','url' => array('/site/index'),array(
            'label' => 'Dropdown <b class="caret"></b>','submenuOptions' => array('class' => 'dropdown-menu'),'items' => array(
                array(
                    'label' => 'Submenu Item 1','url' => array('/user/create'),array(
                    'label' => 'Submenu Item 1','url' => array('/user/list'),'itemOptions' => array('class' => 'dropdown'),'linkOptions' => array('class' => 'dropdown-toggle','data-toggle' => 'dropdown'),));
?>
原文链接:https://www.f2er.com/php/132046.html

猜你在找的PHP相关文章