How to place *Bootstrap* (`glyphicon-bootstrap`) icons in the Yii framework menu

Asked

Viewed 943 times

2

I am starting a project in the company where I develop, and we are being thank you using the Yii Framework along with the Bootstrap, but I’m not getting the icons of Bootstrap (glyphicon-bootstrap) in the menu, follow example of the code:

$this->widget('zii.widgets.CMenu',
   array('htmlOptions'=>array("class"=>"nav", "id"=>"side-menu"), 'items'=>array(
        array('label'=>'Home', 'url'=>array('/site/index')),
        array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
        array('label'=>'Contact', 'url'=>array('/site/contact'), 'className '=>'tafaera'),
        array('label'=>'Charts', 'url'=>array('/submenu/sub0'),
            'submenuOptions'=>array('class'=>'nav nav-second-level'),
            'items'=>array(
                    array('label'=>'Sub 1.1','tag'=>'tafarel' ,'url'=>array('/submenu/sub1')),
                    array('label'=>'Sub 1.2', 'url'=>array('/submenu/sub2')),
                    array('label'=>'Sub 1.3','url'=>array('/submenu/sub3')
                )
            )
        ),
        array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
        array('label'=>'Hola', 'url'=>array('/hola/index')),
        array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
    ),
));

inserir a descrição da imagem aqui

1 answer

1


Put this option 'encodeLabel'=>false, same example below.

$this->widget('zii.widgets.CMenu', 
     array('encodeLabel'=>false, ....

In your code:

$this->widget('zii.widgets.CMenu',
   array("encodeLabel"=>false, 'htmlOptions'=>array("class"=>"nav", "id"=>"side-menu"), 'items'=>array(
        array('label'=>'<i class=""></i> Home', 'url'=>array('/site/index')),
        array('label'=>'<i class=""></i> About', 'url'=>array('/site/page', 'view'=>'about')),
        array('label'=>'<i class=""></i> Contact', 'url'=>array('/site/contact'), 'className '=>'tafaera'),
        array('label'=>'<i class=""></i> Charts', 'url'=>array('/submenu/sub0'),
            'submenuOptions'=>array('class'=>'nav nav-second-level'),
            'items'=>array(
                    array('label'=>'Sub 1.1','tag'=>'tafarel' ,'url'=>array('/submenu/sub1')),
                    array('label'=>'Sub 1.2', 'url'=>array('/submenu/sub2')),
                    array('label'=>'Sub 1.3','url'=>array('/submenu/sub3')
                )
            )
        ),
        array('label'=>'<i class=""></i> Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
        array('label'=>'<i class=""></i> Hola', 'url'=>array('/hola/index')),
        array('label'=>'<i class=""></i> Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
    ),
));

In that Link - How do I add image into Cmenu, has the explanation of some users

  • It didn’t work... Yii still doesn’t recognize the <i class="" tag of the bootstrap, it puts the text instead of the icon

  • I think it’s the place that’s wrong, I changed the place take a look! see if it works @Tafarel_brayan

  • 1

    Now, it worked out.... i tbm did a test going to: framework>Zii>widgets>Cmenu.php There is a public option $encodeLabel=true; and put with ofalse and tbm worked !

  • @Tafarel_brayan was really the place is that it is so much array that I got lost kkkkk but, that good worked out solves the issue ....

  • I’m a beginner... ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.