Class kartik\icons\Icon

Inheritancekartik\icons\Icon

Icon is a class for setting up icon frameworks to work with Yii in an easy way To setup a global default icon framework, you can set the Yii param 'icon-framework' to one of the following values in your config file:

  • 'bsg' for Bootstrap Glyphicons
  • 'fa_' for Font Awesome Icons
  • 'el' for Elusive Font Icons
  • 'typ' for Typicon Font Icons
  • 'whhg' for Web Hosting Hub Glyphs Icons
  • 'jui' for JQuery UI Icons
  • 'uni' for Unicode Icons
  • 'oct' for Github Octicons
  • 'si' for Socicon Icons
  • 'fi' for FlagIcon Icons
  • 'oi' for Open Iconic Icons
  • 'icf' for IcoFont Icons

Public Methods

Hide inherited methods

MethodDescriptionDefined By
addFramework() Add a custom icon set to the icon frameworks kartik\icons\Icon
getFrameworkPrefix() Returns the prefix for the css framework set (or parses framework setup in Yii parameters) kartik\icons\Icon
map() Maps the icon framework to the current view. Call this in your view or layout file. kartik\icons\Icon
show() Displays an icon for a specific framework. kartik\icons\Icon
showLayers() Displays an icon layer stack as supported by Font Awesome 5 kartik\icons\Icon
showStack() Displays an icon stack as supported by frameworks like Font Awesome kartik\icons\Icon

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
getFramework() Returns the key for css framework set (or parses framework setup in Yii parameters) kartik\icons\Icon

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
BSG 'bsg' kartik\icons\Icon
EL 'el' kartik\icons\Icon
FA 'fa' kartik\icons\Icon
FAB 'fab' kartik\icons\Icon
FAD 'faD' kartik\icons\Icon
FAL 'fal' kartik\icons\Icon
FAR 'far' kartik\icons\Icon
FAS 'fas' kartik\icons\Icon
FI 'fi' kartik\icons\Icon
FRAMEWORK_INVALID "Invalid or non-existing framework '{framework}' called in your {method}() method." kartik\icons\Icon
ICF 'icf' kartik\icons\Icon
JUI 'jui' kartik\icons\Icon
NS '\\kartik\\icons\\' kartik\icons\Icon
OCT 'oct' kartik\icons\Icon
OI 'oi' kartik\icons\Icon
PARAM_INVALID "Invalid or non-recognized 'icon-framework' has been setup in Yii params. Check your configuration file." kartik\icons\Icon
PARAM_NOT_SET "The 'icon-framework' option has not been setup in Yii params. Check your configuration file." kartik\icons\Icon
SI 'si' kartik\icons\Icon
TYP 'typ' kartik\icons\Icon
UNI 'uni' kartik\icons\Icon
WHHG 'whhg' kartik\icons\Icon

Method Details

addFramework() public static method

Add a custom icon set to the icon frameworks

public static void addFramework ( $key, $config )
$key string

The key used to identify the icon set

$config array

The icon configuration

getFramework() protected static method

Returns the key for css framework set (or parses framework setup in Yii parameters)

protected static string getFramework ( $framework null, $method 'show' )
$framework string

The framework to be used with the application

$method string

The method in the Icon class (defaults to show)

throws yii\base\InvalidConfigException
getFrameworkPrefix() public static method

Returns the prefix for the css framework set (or parses framework setup in Yii parameters)

public static string getFrameworkPrefix ( $framework null, $method 'show' )
$framework
$method string

The method in the Icon class (defaults to show)

return string

The icon framework key

throws yii\base\InvalidConfigException
map() public static method

Maps the icon framework to the current view. Call this in your view or layout file.

public static void map ( $view, $framework null )
$view yii\web\View

The view object

$framework string

The name of the framework, if not passed it will default to the Yii config param 'icon-framework'

throws yii\base\InvalidConfigException
show() public static method

Displays an icon for a specific framework.

public static string show ( $name, $options = [], $framework null, $space true, $tag 'i', $fa5 'fas' )
$name string

The icon name

$options array

The HTML attributes for the icon. The following special attributes are supported:

  • framework: string, the icon framework name. If not passed will default to the icon-framework param set in Yii Configuration file. Will throw an InvalidConfigException if neither of the two is available.
  • space: boolean, whether to place a space after the icon, defaults to true
  • tag: string, the HTML tag to wrap the icon (defaults to i).
$framework string

Deprecated since v1.4.5 (use/see $options above)

$space boolean

Deprecated since v1.4.5 (use/see $options above)

$tag string

Deprecated since v1.4.5 (use/see $options above)

$fa5 string

Deprecated since v1.4.5

return string

The HTML formatted icon

throws yii\base\InvalidConfigException
showLayers() public static method

Displays an icon layer stack as supported by Font Awesome 5

See also https://fontawesome.com/how-to-use/svg-with-js#layering.

public static string showLayers ( $items = [], $options = [] )
$items array

The icons to be displayed in the layer, each of which is an array consisting of following configuration e.g. ['name'=>'play', 'framework' => Icon::FAS, 'options' => [], 'text' => NULL, 'tag' => NULL]:

  • name: string, the name for the icon; or layers-text for text or layers-counter for counter
  • text: string, the text within the span container
  • framework: string, the icon framework name to use for determining icon prefixes. If not set will default to Icon::FAS. Will throw an InvalidConfigException if the framework set is invalid.
  • tag: string, the HTML tag for the icon, defaults to i for non-text layers and span for text layers
  • options: array, the html attributes for the layer item container
$options array

The html attributes for the layers main container. The following special attributes are supported:

  • space: boolean, whether to place a space after the icon, defaults to true.
  • tag: string, the HTML tag to wrap the icon (defaults to span).
return string

The html formatted icon

throws yii\base\InvalidConfigException
showStack() public static method

Displays an icon stack as supported by frameworks like Font Awesome

See also http://fontawesome.io/examples/#stacked.

public static string showStack ( $name1, $name2, $options = [], $options1 = [], $options2 = [] )
$name1 string

The icon name in stack 1x

$name2 string

The icon name in stack 2x

$options array

The HTML attributes for the icon stack container. The following special attributes are supported:

  • invert: bool, whether to invert the order of stack 2x and 1x and place stack-1x before stack-2x. Defaults to false.
  • tag: string, the html tag to wrap the stack container (defaults to span).
  • prefix: string, the CSS prefix string for the stack container (defaults to fa-stack).
  • space: boolean, whether to place a space after the icon, defaults to true
$options1 array

The HTML attributes for the icon in stack 1x. The following special attributes are supported:

  • framework: string, the icon framework name. If not passed will default to the icon-framework param set in Yii Configuration file. Will throw an InvalidConfigException if neither of the two is available.
  • space: boolean, whether to place a space after the icon, defaults to true.
  • tag: string, the HTML tag to wrap the icon (defaults to i).
$options2 array

The HTML attributes for the icon in stack 2x. The following special attributes are supported:

  • framework: string, the icon framework name. If not passed will default to the icon-framework param set in Yii Configuration file. Will throw an InvalidConfigException if neither of the two is available.
  • space: boolean, whether to place a space after the icon, defaults to true.
  • tag: string, the HTML tag to wrap the icon (defaults to i).
return string

The html formatted icon

throws yii\base\InvalidConfigException