yii2-icons Set of icon frameworks for easy use in Yii Framework 2.0

  1. Requirements
  2. Installation
  3. Usage
  4. Report
  5. License
  6. Resources

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

Requirements

  • 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.

Installation

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.

Usage

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;
Icon::map($this);  
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

Report

License

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

Resources

3 2
48 followers
0 downloads
Yii Version: 2.0
License: BSD-2-Clause
Category: User Interface
Developed by: Kartik V
Created on: Dec 7, 2013
Last updated: 10 years ago

Related Extensions