Yii2 – adding icon in menu with yii2-simpleapp class
I have worked to enhance the yii2 core Nav class for adding extra parameter that will get icon class for the menu items. You can find it at: SimpleNav – https://github.com/azraf/yii2-simpleapp/blob/master/classes/SimpleNav.php
Its also part of Yii2-simpleapp package. If you are already using my Yii2-simple or Yii2-advancedapp, that case, just update your composer via command
composer update , and the class will be right into your application.
How to use:
Using of this class is very easy. If you are using Yii2-simple or Yii2-advancedapp, whenever you need to add icon within the menu items, just instantiate it instead of the
yii\bootstrap\Nav in your
Comment out the line:
// use yii\bootstrap\Nav;
Add this line:
use azraf\simpleapp\classes\SimpleNav as Nav;
You now all set up.
Now you can use icon as-
'items' => [ [ 'label' => 'Home', 'url' => ['site/index'], 'linkOptions' => [ 'class'=>'active', 'i_class'=>'fa fa-dashboard', 'i_class_right'=>'fa fa-angle-left pull-right' ], ], ]
This will render:
<li class="active"> <a class="active" href="/index.php/site/index"> <i class="fa fa-dashboard"></i> Home <i class="fa fa-angle-left pull-right"></i> </a> </li>
You also may use the class independently into your project. All you need is Download the SimpleNav class file, place it in your components or controllers folder (where you feel suitable), then change the namespace accordingly. Rest all steps are same.
Leave a Reply
You must be logged in to post a comment.