Yii 2.0: yii2-icons

Set of icon frameworks for easy use in Yii Framework 2.0

This extension offers an easy method to setup various icon frameworks to work with Yii Framework 2.0. Most popular and free icon frameworks available are currently supported. This list may be extended in future based on demand and feedback.

  1. Font Awesome
  2. Elusive Icons
  3. Typicons
  4. Web Hosting Hub Glyphs
  5. JQuery UI Icons


  • Yii 2.0 (dev-master)
  • PHP 5.4
  • Twitter Bootstrap 3.0 (for certain icon frameworks)

Note: This extension mandatorily requires Yii Framework 2. The framework is under active development and the first stable release of Yii 2 is expected in early 2014.


The preferred way to install this extension is through composer.

Either run:

$ php composer.phar require kartik-v/yii2-icons"dev-master"

or add:

"kartik-v/yii2-icons": "dev-master"

to the require section of your composer.json file.


Global Setup

In case you wish to setup one Icon framework globally, set the parameter icon-framework in the params array of your Yii Configuration File.

'params' => [
  'icon-framework' => 'fa',  // Font Awesome Icon framework

To initialize the globally setup framework in your view, call this code in your view or view layout file.

use kartik\icons\Icon;

Per View Setup

You can also call each icon-framework individually in your view or view layout like below. Map any icon framework within each view as in the example below.

use kartik\icons\Icon;
Icon::map($this, Icon::EL); // Maps the Elusive icon font framework

Displaying Icons

After mapping your icon framework with one of the options above, you can display icons using Icon::show method. Icons can be displayed using one of the options below:

use kartik\icons\Icon;
// Option 1: Uses the `icon-framework` setup in Yii config params. 
echo Icon::show('user'); 
// Option 2: Specific Icon Call in a view. Additional options can also be passed to style the icon.
echo Icon::show('user', ['class'=>'fa-2x'], Icon::FA);

Note: The kartik\icons\Icon::show method outputs a HTML formatted text. So in order to display icons in Yii-2 components like Navbar or Nav, you must set encodeLabels to false.

$items = [
    ['label' => Icon::show('home') . 'Home', 'url' => ['/site/index']],
// Your other code
/* Note you must encodeLabels to false to display icons in labels */
echo \yii\bootstrap\Nav::widget([
    'items' => $items,
    'encodeLabels' => false
// Your other code



yii2-icons is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.


Total 4 comments

#17034 report it
Kartik V at 2014/04/27 10:13am
2 new icon frameworks added
  1. Krajee's Uni Icons - Unicode Symbols made available as CSS. Refer demo here.
  2. Bootstrap Glyphicons added to the list of frameworks.

Check the updated extension demo.

#15720 report it
Kartik V at 2013/12/09 10:30pm
Re: how to show in navbar

Use the project page or forum to report issues.

This is more a configuration at the Nav Widget level. Read the docs/code comments for Yii2 Bootstrap extension. The Yii2 Navbar uses Nav widget to generate menus. Note: The kartik\icons\Icon will generate HTML code. So in your Nav::widget you should use encodeLabels => false to not Html encode icons in labels. For example:

use kartik\icons\Icon;
$items = [
    ['label' => Icon::show('home') . 'Home', 'url' => ['/site/index']],
NavBar::begin(['brandLabel' => 'My Application']);
/* Note you must encodeLabels to false to display icons in labels */
echo \yii\bootstrap\Nav::widget([
    'items' => $items,
    'encodeLabels' => false
#15717 report it
belmanski at 2013/12/09 04:46pm
how to show in navbar ?

When I try to show an icon in the navbar before the text I get:

thnx for helping.

#15707 report it
Kartik V at 2013/12/08 10:41pm
Re: yii2-icons support for version ?

Could not get you. If its the Yii version - you are talking about... the yii2-icons extension requires Yii Framework 2.0. Note Yii Framework 2.0 is under active development and stable version is not out yet (read disclaimer). For this extension, you can refer the documentation and usage at the demo site.

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet