PHP code example of kartik-v / yii2-icons

1. Go to this page and download the library: Download kartik-v/yii2-icons library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kartik-v / yii2-icons example snippets


'params' => [
  'icon-framework' => \kartik\icons\Icon::FAS,  // Font Awesome Icon framework
]

use kartik\icons\Icon;
Icon::map($this);  

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

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', 'framework' => Icon::FAS]); 

$items = [
    ['label' => Icon::show('home') . 'Home', 'url' => ['/site/index']],
];

// Your other code

/* Note you must encodeLabels to false to display icons in labels */
echo \kartik\nav\NavX::widget([
    'items' => $items,
    'encodeLabels' => false
]);

// Your other code

use kartik\icons\Icon;
// fa-twitter on fa-square
 Icon::showStack('twitter', 'square', ['class'=>'fa-lg'], ['framework' => Icon::FAB], ['framework' => Icon::FAR])

// fa-flag on fa-circle
 Icon::showStack('flag', 'circle', ['class'=>'fa-lg'], ['class'=>'fa-inverse']);

use kartik\icons\Icon;
// add framework
Icon::addFramework('custom', [
    'class' => '\common\icons\CustomIconAsset',
    'prefix' => 'custom-icon',
]);

// map to view file
Icon::map($this, 'custom');

// show the icon
echo Icon::show('menu',['framework' => 'custom']);

namespace common\icons;
class CustomIconAsset extends \yii\web\AssetBundle
{
    public $sourcePath = '@common/icons/assets/custom';
    public $depends = array(
        'yii\web\YiiAsset',
        'yii\bootstrap4\BootstrapAsset'
    );
    public $css=[
        'css/animation.css',
        'css/custom-codes.css',
        'css/custom-embedded.css',
        'css/custom-ie7.css',
        'css/custom-ie7-codes.css',
        'css/custom.css',
    ];
}