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.
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 setencodeLabels
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 ¶
- Report any issues on the project page
- Use the forum page for any discussions on this extension
License ¶
yii2-icons is released under the BSD 3-Clause License. See the bundled LICENSE.md
for details.
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.
how to show in navbar ?
When I try to show an icon in the navbar before the text I get:
thnx for helping.
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 yourNav::widget
you should useencodeLabels => 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 ]); NavBar::end();
2 new icon frameworks added
Check the updated extension demo.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.