Class kartik\helpers\Html

Inheritancekartik\helpers\Html » yii\helpers\Html » yii\helpers\BaseHtml
Available since version2.0

Html provides a set of static methods for generating commonly used HTML tags and extends yii\helpers\Html with additional bootstrap styled components and markup.

Nearly all of the methods in this class allow setting additional html attributes for the html tags they generate. You can specify for example. 'class', 'style' or 'id' for an html element using the $options parameter. See the documentation of the tag() method for more details.

For example,

use kartik\helpers\Html;

echo Html::checkboxButtonGroup('cbx', [1, 2], [1 => 'Check 1', 2 => 'Check 2', 3 => 'Check 3']);

See also:

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$attributeOrder array The preferred order of attributes in a tag. yii\helpers\BaseHtml
$attributeRegex string Regular expression used for attribute name validation. yii\helpers\BaseHtml
$dataAttributes array List of tag attributes that should be specially handled when their values are of array type. yii\helpers\BaseHtml
$normalizeClassAttribute boolean Whether to removes duplicate class names in tag attribute class yii\helpers\BaseHtml
$voidElements array List of void elements (element name => 1) yii\helpers\BaseHtml

Public Methods

Hide inherited methods

MethodDescriptionDefined By
a() Generates a hyperlink tag. yii\helpers\BaseHtml
abbr() Generates a bootstrap abbreviation. kartik\helpers\Html
activeCheckbox() Generates a checkbox tag together with a label for the given model attribute. yii\helpers\BaseHtml
activeCheckboxButtonGroup() Generates an active bootstrap checkbox button group. A checkbox button group allows multiple selection, like listBox(). As a result, the corresponding submitted value is an array. The selection of the checkbox button group is taken from the value of the model attribute. kartik\helpers\Html
activeCheckboxList() Generates a list of checkboxes. yii\helpers\BaseHtml
activeDropDownList() Generates a drop-down list for the given model attribute. yii\helpers\BaseHtml
activeFileInput() Generates a file input tag for the given model attribute. yii\helpers\BaseHtml
activeHiddenInput() Generates a hidden input tag for the given model attribute. yii\helpers\BaseHtml
activeHint() Generates a hint tag for the given model attribute. yii\helpers\BaseHtml
activeInput() Generates an input tag for the given model attribute. yii\helpers\BaseHtml
activeLabel() Generates a label tag for the given model attribute. yii\helpers\BaseHtml
activeListBox() Generates a list box. yii\helpers\BaseHtml
activePasswordInput() Generates a password input tag for the given model attribute. yii\helpers\BaseHtml
activeRadio() Generates a radio button tag together with a label for the given model attribute. yii\helpers\BaseHtml
activeRadioButtonGroup() Generates an active bootstrap radio button group. A radio button group is like a checkbox button group, except that it only allows single selection. The selection of the radio buttons is taken from the value of the model attribute. kartik\helpers\Html
activeRadioList() Generates a list of radio buttons. yii\helpers\BaseHtml
activeTextInput() Generates a text input tag for the given model attribute. yii\helpers\BaseHtml
activeTextarea() Generates a textarea tag for the given model attribute. yii\helpers\BaseHtml
addCssClass() Adds a CSS class (or several classes) to the specified options. yii\helpers\BaseHtml
addCssStyle() Adds the specified CSS style to the HTML options. yii\helpers\BaseHtml
address() Generates a bootstrap address block. kartik\helpers\Html
badge() Generates a badge. kartik\helpers\Html
beginForm() Generates a form start tag. yii\helpers\BaseHtml
beginTag() Generates a start tag. yii\helpers\BaseHtml
blockquote() Generates a bootstrap blockquote. kartik\helpers\Html
bsLabel() Generates a bootstrap label markup. kartik\helpers\Html
button() Generates a button tag. yii\helpers\BaseHtml
buttonInput() Generates an input button. yii\helpers\BaseHtml
caret() Generates a bootstrap caret. kartik\helpers\Html
checkbox() Generates a checkbox input. yii\helpers\BaseHtml
checkboxButtonGroup() Generates a bootstrap checkbox button group. A checkbox button group allows multiple selection, like listBox(). As a result, the corresponding submitted value is an array. kartik\helpers\Html
checkboxList() Generates a list of checkboxes. yii\helpers\BaseHtml
closeButton() Generates a generic bootstrap close icon button for dismissing content like modals and alerts. kartik\helpers\Html
csrfMetaTags() Generates the meta tags containing CSRF token information. yii\helpers\BaseHtml
cssFile() Generates a link tag that refers to an external CSS file. yii\helpers\BaseHtml
cssStyleFromArray() Converts a CSS style array into a string representation. yii\helpers\BaseHtml
cssStyleToArray() Converts a CSS style string into an array representation. yii\helpers\BaseHtml
decode() Decodes special HTML entities back to the corresponding characters. yii\helpers\BaseHtml
encode() Encodes special characters into HTML entities. yii\helpers\BaseHtml
endForm() Generates a form end tag. yii\helpers\BaseHtml
endTag() Generates an end tag. yii\helpers\BaseHtml
error() Generates a tag that contains the first validation error of the specified model attribute. yii\helpers\BaseHtml
errorSummary() Generates a summary of the validation errors. yii\helpers\BaseHtml
escapeJsRegularExpression() Escapes regular expression to use in JavaScript. yii\helpers\BaseHtml
fileInput() Generates a file input field. yii\helpers\BaseHtml
getAttributeName() Returns the real attribute name from the given attribute expression. yii\helpers\BaseHtml
getAttributeValue() Returns the value of the specified attribute name or expression. yii\helpers\BaseHtml
getButtonGroup() Generates a bootstrap toggle button group (checkbox or radio type) kartik\helpers\Html
getInputId() Generates an appropriate input ID for the specified attribute name or expression. yii\helpers\BaseHtml
getInputIdByName() Converts input name to ID. yii\helpers\BaseHtml
getInputName() Generates an appropriate input name for the specified attribute name or expression. yii\helpers\BaseHtml
hiddenInput() Generates a hidden input field. yii\helpers\BaseHtml
icon() Generates a bootstrap icon markup. kartik\helpers\Html
img() Generates an image tag. yii\helpers\BaseHtml
input() Generates an input type of the given type. yii\helpers\BaseHtml
jsFile() Generates a script tag that refers to an external JavaScript file. yii\helpers\BaseHtml
jumbotron() Generates a jumbotron - a lightweight, flexible component that can optionally extend the entire viewport to showcase key content on your site. kartik\helpers\Html
label() Generates a label tag. yii\helpers\BaseHtml
listBox() Generates a list box. yii\helpers\BaseHtml
listGroup() Generates a list group. Flexible and powerful component for displaying not only simple lists of elements, but complex ones with custom content. kartik\helpers\Html
mailto() Generates a mailto hyperlink. yii\helpers\BaseHtml
media() Generates a bootstrap media object. Abstract object styles for building various types of components (like blog comments, Tweets, etc) that feature a left-aligned or right-aligned image alongside textual content. kartik\helpers\Html
mediaList() Generates bootstrap list of media (useful for comment threads or articles lists). kartik\helpers\Html
ol() Generates an ordered list. yii\helpers\BaseHtml
pageHeader() Generates a page header. kartik\helpers\Html
panel() Generates a panel for boxing content. kartik\helpers\Html
passwordInput() Generates a password input field. yii\helpers\BaseHtml
radio() Generates a radio button input. yii\helpers\BaseHtml
radioButtonGroup() Generates a bootstrap radio button group. A radio button group is like a checkbox button group, except that it only allows single selection. kartik\helpers\Html
radioList() Generates a list of radio buttons. yii\helpers\BaseHtml
removeCssClass() Removes a CSS class from the specified options. yii\helpers\BaseHtml
removeCssStyle() Removes the specified CSS style from the HTML options. yii\helpers\BaseHtml
renderSelectOptions() Renders the option tags that can be used by dropDownList() and listBox(). yii\helpers\BaseHtml
renderTagAttributes() Renders the HTML tag attributes. yii\helpers\BaseHtml
resetButton() Generates a reset button tag. yii\helpers\BaseHtml
resetInput() Generates a reset input button. yii\helpers\BaseHtml
script() Generates a script tag. yii\helpers\BaseHtml
style() Generates a style tag. yii\helpers\BaseHtml
submitButton() Generates a submit button tag. yii\helpers\BaseHtml
submitInput() Generates a submit input button. yii\helpers\BaseHtml
tag() Generates a complete HTML tag. yii\helpers\BaseHtml
textInput() Generates a text input field. yii\helpers\BaseHtml
textarea() Generates a text area input. yii\helpers\BaseHtml
ul() Generates an unordered list. yii\helpers\BaseHtml
well() Generates a well container. kartik\helpers\Html

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
activeBooleanInput() Generates a boolean input This method is mainly called by activeCheckbox() and activeRadio(). yii\helpers\BaseHtml
activeListInput() Generates a list of input fields. yii\helpers\BaseHtml
booleanInput() Generates a boolean input. yii\helpers\BaseHtml
getListGroupItem() Processes and generates each list group item kartik\helpers\Html
getMediaItem() Processes and generates each media item kartik\helpers\Html
getMediaList() Processes media items array to generate a recursive list. kartik\helpers\Html
getPanelContent() Generates panel content kartik\helpers\Html
getPanelTitle() Generates panel title for heading and footer. kartik\helpers\Html
hasCssClass() Check if HTML options has specified CSS class kartik\helpers\Html
setActivePlaceholder() Generate placeholder from model attribute label. yii\helpers\BaseHtml

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
CLEAR_FLOAT 'clearfix' Bootstrap clear floats CSS kartik\helpers\Html
FLOAT_CENTER 'center-block' Bootstrap centered block CSS kartik\helpers\Html
FLOAT_LEFT 'pull-left' Bootstrap float left CSS kartik\helpers\Html
FLOAT_RIGHT 'pull-right' Bootstrap float right CSS kartik\helpers\Html
HIDDEN 'hidden' Bootstrap CSS for hidden items kartik\helpers\Html
IMAGE_REPLACER 'text-hide' Bootstrap CSS for image replacer to hide text kartik\helpers\Html
INVISIBLE 'invisible' Bootstrap CSS for invisible items kartik\helpers\Html
SCREEN_READER 'sr-only' Bootstrap CSS for screen reader display kartik\helpers\Html
SHOW 'show' Bootstrap CSS for visible items kartik\helpers\Html
SIZE_LARGE 'lg' Bootstrap large size modifier kartik\helpers\Html
SIZE_MEDIUM 'md' Bootstrap medium size modifier (this is the default size) kartik\helpers\Html
SIZE_SMALL 'sm' Bootstrap small size modifier kartik\helpers\Html
SIZE_TINY 'xs' Bootstrap extra small size modifier kartik\helpers\Html
TYPE_DANGER 'danger' The danger bootstrap contextual color type kartik\helpers\Html
TYPE_DEFAULT 'default' The default bootstrap contextual color type kartik\helpers\Html
TYPE_INFO 'info' The information bootstrap contextual color type kartik\helpers\Html
TYPE_PRIMARY 'primary' The primary bootstrap contextual color type kartik\helpers\Html
TYPE_SUCCESS 'success' The success bootstrap contextual color type kartik\helpers\Html
TYPE_WARNING 'warning' The warning bootstrap contextual color type kartik\helpers\Html

Method Details

abbr() public static method

Generates a bootstrap abbreviation.

Example:

echo Html::abbr('HTML', 'HyperText Markup Language')  . ' is the best thing since sliced bread';
echo Html::abbr('HTML', 'HyperText Markup Language', true);

See also http://getbootstrap.com/css/#type-abbreviations.

public static string abbr ( $content, $title, $initialism false, $options = [] )
$content string

The abbreviation content

$title string

The abbreviation title

$initialism boolean

If set to true, will display a slightly smaller font-size.

$options array

Html options for the abbreviation

activeCheckboxButtonGroup() public static method

Generates an active bootstrap checkbox button group. A checkbox button group allows multiple selection, like listBox(). As a result, the corresponding submitted value is an array. The selection of the checkbox button group is taken from the value of the model attribute.

Example:

echo Html::activeCheckboxButtonGroup($model, 'attr', [1 => 'Check 1', 2 => 'Check 2', 3 => 'Check 3']);

See also http://getbootstrap.com/javascript/#buttons-checkbox-radio.

public static string activeCheckboxButtonGroup ( $model, $attribute, $items, $options = [] )
$model yii\base\Model

The model object

$attribute string

The attribute name or expression. See getAttributeName() for the format about attribute expression.

$items array

The data item used to generate the checkboxes. The array keys are the checkbox values, and the array values are the corresponding labels. Note that the labels will NOT be HTML-encoded, while the values will.

$options array

Options (name => config) for the checkbox list container tag. The following options are specially handled:

  • tag: string, the tag name of the container element.
  • unselect: string, the value that should be submitted when none of the checkboxes is selected. You may set this option to be null to prevent default value submission. If this option is not set, an empty string will be submitted.
  • encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if item option is set.
  • separator: string, the HTML code that separates items.
  • itemOptions: array, the options for generating the checkbox tag using checkbox().
  • item: Closure, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:

    function ($index, $label, $name, $checked, $value)
    

    where $index is the zero-based index of the checkbox in the whole list; $label is the label for the checkbox; and $name, $value and $checked represent the name, value and the checked status of the checkbox input.

See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated bootstrap checkbox button group

activeRadioButtonGroup() public static method

Generates an active bootstrap radio button group. A radio button group is like a checkbox button group, except that it only allows single selection. The selection of the radio buttons is taken from the value of the model attribute.

Example:

echo Html::activeRadioButtonGroup($model, 'attr', [1 => 'Option 1', 2 => 'Option 2', 3 => 'Option 3']);

See also http://getbootstrap.com/javascript/#buttons-checkbox-radio.

public static string activeRadioButtonGroup ( $model, $attribute, $items, $options = [] )
$model yii\base\Model

The model object

$attribute string

The attribute name or expression. See getAttributeName() for the format about attribute expression.

$items array

The data item used to generate the radio buttons. The array keys are the radio values, and the array values are the corresponding labels. Note that the labels will NOT be HTML-encoded, while the values will.

$options array

Options (name => config) for the radio button list container tag. The following options are specially handled:

  • tag: string, the tag name of the container element.
  • unselect: string, the value that should be submitted when none of the radio buttons is selected. By setting this option, a hidden input will be generated.
  • encode: boolean, whether to HTML-encode the radio button labels. Defaults to true. This option is ignored if item option is set.
  • separator: string, the HTML code that separates items.
  • itemOptions: array, the options for generating the radio button tag using radio().
  • item: Closure, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:

    function ($index, $label, $name, $checked, $value)
    

    where $index is the zero-based index of the radio button in the whole list; $label is the label for the radio button; and $name, $value and $checked represent the name, value and the checked status of the radio button input.

See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated bootstrap radio button group

address() public static method

Generates a bootstrap address block.

Example:

echo Html::address(
     'Twitter, Inc.',
     ['795 Folsom Ave, Suite 600', 'San Francisco, CA 94107'],
     ['Res' => '(123) 456-7890', 'Off'=> '(456) 789-0123'],
     ['Res' => 'first.last@example.com', 'Off' => 'last.first@example.com']
);
$address = Html::address(
     'Twitter, Inc.',
     ['795 Folsom Ave, Suite 600', 'San Francisco, CA 94107'],
     ['Res' => '(123) 456-7890', 'Off'=> '(456) 789-0123'],
     ['Res' => 'first.last@example.com', 'Off' => 'last.first@example.com'],
     Html::icon('phone'),
     Html::icon('envelope')
);
echo Html::well($address, Html::SIZE_TINY);

See also http://getbootstrap.com/css/#type-addresses.

public static string address ( $name, $lines = [], $phone = [], $email = [], $options = [], $phoneLabel '(P)', $emailLabel '(E)' )
$name string

The addressee name.

$lines array

The lines of address information.

$phone array

The list of phone numbers - passed as $key => $value, where:

  • $key: string, is the phone type could be 'Res', 'Off', 'Cell', 'Fax'.
  • $value: string, is the phone number.
$email array

The list of email addresses - passed as $key => $value, where:

  • $key: string, is the email type could be 'Res', 'Off'.
  • $value: string, is the email address.
$options array

Html options for the address.

$phoneLabel string

The prefix label for each phone - defaults to '(P)'.

$emailLabel string

The prefix label for each email - defaults to '(E)'.

badge() public static method

Generates a badge.

Example:

echo Html::badge('10');
echo Html::badge('20', ['font-size' => '16px']);

See also http://getbootstrap.com/components/#badges.

public static string badge ( $content, $options = [], $tag 'span' )
$content string

The badge content

$options array

HTML attributes / options for the label container

$tag string

The label container tag. Defaults to 'span'.

throws Exception
blockquote() public static method

Generates a bootstrap blockquote.

Example:

echo Html::blockquote(
     'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.',
     'Someone famous in {source}',
     'International Premier League',
     'IPL'
);

See also http://getbootstrap.com/css/#type-blockquotes.

public static string blockquote ( $content, $citeContent '', $citeTitle '', $citeSource '', $options = [], $contentOptions = [], $footerOptions = [] )
$content string

The blockquote content

$citeContent string

The content of the citation (optional) - this should typically include the tag '{source}' to embed the cite source

$citeTitle string

The cite source title (optional)

$citeSource string

The cite source (optional)

$options array

HTML attributes for the blockquote main container

$contentOptions array

HTML attributes for the blockquote content container. For Bootstrap 4.x, the CSS class mb-0 will be set if the class attribute is not set. The following option is specially recognized:

  • tag: string, the tag to render the content. Defaults to p.
$footerOptions array

HTML attributes for the blockquote footer container. Applicable only for Bootstrap 4.x releases.

throws Exception
bsLabel() public static method

Generates a bootstrap label markup.

Example:

echo Html::bsLabel('Draft');
echo Html::bsLabel('Inactive', 'danger');
echo Html::bsLabel('Active', 'success');

See also http://getbootstrap.com/components/#labels.

public static string bsLabel ( $content, $type 'default', $options = [], $tag 'span', $prefix null )
$content string

The label content

$type string

The bootstrap label type. Defaults to 'default'. Should be one of the bootstrap contextual colors: 'default, 'primary', 'success', 'info', 'danger', 'warning'.

$options array

HTML attributes / options for the label container

$tag string

The label container tag. Defaults to 'span'.

$prefix string

The CSS class prefix. Defaults to null and will be auto parsed based on BS Version.

throws Exception
caret() public static method

Generates a bootstrap caret.

Example:

echo 'Down Caret ' . Html::caret();
echo 'Up Caret ' . Html::caret('up');
echo 'Disabled Caret ' . Html::caret('down', true);

See also http://getbootstrap.com/css/#helper-classes-carets.

public static string caret ( $direction 'down', $disabled false, $options = [], $tag 'span' )
$direction string

Whether to display as 'up' or 'down' direction. Defaults to down.

$disabled boolean

If the caret is to be displayed as disabled. Defaults to false.

$options array

Html options for the caret container.

$tag string

The html tag for rendering the caret. Defaults to span.

checkboxButtonGroup() public static method

Generates a bootstrap checkbox button group. A checkbox button group allows multiple selection, like listBox(). As a result, the corresponding submitted value is an array.

Example:

echo Html::checkboxButtonGroup('cbx', [1, 2], [1 => 'Check 1', 2 => 'Check 2', 3 => 'Check 3']);

See also http://getbootstrap.com/javascript/#buttons-checkbox-radio.

public static string checkboxButtonGroup ( $name, $selection null, $items = [], $options = [] )
$name string

The name attribute of each checkbox.

$selection string|array

The selected value(s).

$items array

The data item used to generate the checkboxes. The array keys are the checkbox values, while the array values are the corresponding labels.

$options array

Options (name => config) for the checkbox list container tag. The following options are specially handled:

  • tag: string, the tag name of the container element.
  • unselect: string, the value that should be submitted when none of the checkboxes is selected. You may set this option to be null to prevent default value submission. If this option is not set, an empty string will be submitted.
  • encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if item option is set.
  • separator: string, the HTML code that separates items.
  • itemOptions: array, the options for generating the checkbox tag using checkbox().
  • item: Closure, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:

    function ($index, $label, $name, $checked, $value)
    

    where $index is the zero-based index of the checkbox in the whole list; $label is the label for the checkbox; and $name, $value and $checked represent the name, value and the checked status of the checkbox input.

See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated checkbox button group

closeButton() public static method

Generates a generic bootstrap close icon button for dismissing content like modals and alerts.

Example:

echo Html::closeButton();
echo Html::closeButton(Html::icon('remove-sign');

See also http://getbootstrap.com/css/#helper-classes-close.

public static string closeButton ( $label '×', $options = [], $tag 'button' )
$label string

The close icon label. Defaults to ×.

$options array

HTML attributes / options for the close icon button.

$tag string

The HTML tag for rendering the close icon. Defaults to button.

getButtonGroup() public static method

Generates a bootstrap toggle button group (checkbox or radio type)

See also http://getbootstrap.com/javascript/#buttons-checkbox-radio.

public static string getButtonGroup ( $type, $name, $selection null, $items = [], $options = [] )
$type string

Whether checkbox or radio.

$name string

The name attribute of each checkbox.

$selection string|array

The selected value(s).

$items array

The data item used to generate the checkboxes/radios. The array keys are the checkbox/radio values, while the array values are the corresponding labels.

$options array

Options (name => config) for the checkbox/radio list container tag. The following options are specially handled:

  • tag: string, the tag name of the container element.
  • unselect: string, the value that should be submitted when none of the checkboxes/radios is selected. By setting this option, a hidden input will be generated.
  • encode: boolean, whether to HTML-encode the checkbox/radio labels. Defaults to true. This option is ignored if item option is set.
  • separator: string, the HTML code that separates items.
  • itemOptions: array, the options for generating the checkbox/radio tag using checkbox()/radio().
  • item: Closure, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:

    function ($index, $label, $name, $checked, $value)
    

    where $index is the zero-based index of the checkbox/radio in the whole list; $label is the label for the checkbox/radio; and $name, $value and $checked represent the name, value and the checked status of the checkbox/radio input, respectively.

See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated toggle button group

getListGroupItem() protected static method

Processes and generates each list group item

protected static string getListGroupItem ( $item, $itemOptions = [], $badgeOptions = [] )
$item array

The list item configuration. The following array key properties can be setup:

  • content: string|array, the list item content. When passed as a string, it will display this directly as a raw content. When passed as an array, it requires these keys:
    • heading: string, the content heading (optional).
      • body: string, the content body (optional).
      • headingOptions: array, the HTML attributes / options for heading container (optional).
      • bodyOptions: array, the HTML attributes / options for body container (optional).
  • url: string|array, the url for linking the list item content (optional).
  • badge: string, any badge content to be displayed for this list item (optional)
  • badgeOptions: array, the HTML attributes / options for badge container (optional).
  • active: boolean, to highlight the item as active (applicable only if $url is passed). Defaults to false.
  • options: array, HTML attributes / options for the list group item container (optional).
$itemOptions array

HTML attributes for the list group item options (will be overridden by options at the item level). The following special option is recognized:

  • tag: string, the list group container tag. Defaults to 'div'.
$badgeOptions array

HTML attributes for the list group item badge options (will be overridden by badgeOptions at the item level)

throws Exception
getMediaItem() protected static method

Processes and generates each media item

protected static string getMediaItem ( $item = [], $srcOptions = [], $imgOptions = [], $headingOptions = [], $bodyOptions = [], $itemOptions = [], $tag 'div' )
$item array

The media item configuration

$srcOptions array

Html options for the media article link.

$imgOptions array

Html options for the media image.

$headingOptions array

HTML attributes / options for the media item heading container.

$bodyOptions array

HTML attributes / options for the media item body container.

$itemOptions array

HTML attributes / options for the media item container.

$tag string

The media item container tag

throws Exception
getMediaList() protected static method

Processes media items array to generate a recursive list.

protected static string getMediaList ( $items, $srcOptions = [], $imgOptions = [], $headingOptions = [], $bodyOptions = [], $itemOptions = [] )
$items array

The media items

$srcOptions array

Html options for the media article link.

$imgOptions array

Html options for the media image.

$headingOptions array

HTML attributes / options for the media item heading container.

$bodyOptions array

HTML attributes / options for the media item body container.

$itemOptions array

HTML attributes / options for the media item container.

throws Exception
getPanelContent() protected static method

Generates panel content

protected static string getPanelContent ( $content, $type )
$content array

The panel content components.

$type string

One of the content settings

throws Exception
getPanelTitle() protected static method

Generates panel title for heading and footer.

protected static string getPanelTitle ( $content, $type, $widget )
$content array

The panel content settings.

$type string

Whether heading or footer

$widget kartik\base\Widget

The widget object

throws \Exception|\Exception
hasCssClass() protected static method

Check if HTML options has specified CSS class

protected static boolean hasCssClass ( $options, $cssClass )
$options array

The HTML options

$cssClass string

The css class to test

icon() public static method

Generates a bootstrap icon markup.

Example:

echo Html::icon('pencil');
echo Html::icon('trash', ['style' => 'color: red; font-size: 2em']);
echo Html::icon('plus', ['class' => 'text-success']);

See also http://getbootstrap.com/components/#glyphicons.

public static string icon ( $icon, $options = [], $prefix 'glyphicon glyphicon-', $tag 'span' )
$icon string

The bootstrap icon name without prefix (e.g. 'plus', 'pencil', 'trash')

$options array

HTML attributes / options for the icon container

$prefix string

The css class prefix - defaults to 'glyphicon glyphicon-'

$tag string

The icon container tag (usually 'span' or 'i') - defaults to 'span'

jumbotron() public static method

Generates a jumbotron - a lightweight, flexible component that can optionally extend the entire viewport to showcase key content on your site.

Example:

echo Html::jumbotron(
     '<h1>Hello, world</h1><p>This is a simple jumbotron-style component for calling extra attention to featured
    content or information.</p>'
);
echo Html::jumbotron([
    'heading' => 'Hello, world!',
    'body' => 'This is a simple jumbotron-style component for calling extra attention to featured content or information.'
]);
echo Html::jumbotron([
    'heading' => 'Hello, world!',
    'body' => 'This is a simple jumbotron-style component for calling extra attention to featured content or information.'
    'buttons' => [
         [
             'label' => 'Learn More',
             'icon' => 'book',
             'url' => '#',
             'type' => Html::TYPE_PRIMARY,
             'size' => Html::LARGE
         ],
         [
             'label' => 'Contact Us',
             'icon' => 'phone',
             'url' => '#',
             'type' => Html::TYPE_DANGER,
             'size' => Html::LARGE
         ]
    ]
]);

See also http://getbootstrap.com/components/#jumbotron.

public static string jumbotron ( $content = [], $fullWidth false, $options = [] )
$content string|array

The list item content. When passed as a string, it will display this directly as a raw content. When passed as an array, it requires these keys:

  • heading: string, the jumbotron heading title
  • body: string, the jumbotron content body
  • buttons: array, the configuration for jumbotron buttons. The following properties can be set:
    • label: string, the button label
    • icon: string, the icon to place before the label
    • url: mixed, the button url
    • type: string, one of the bootstrap color modifier constants. Defaults to TYPE_DEFAULT.
    • size: string, one of the size modifier constants
    • options: array, the HTML attributes / options for the button.
$fullWidth boolean

Whether this is a full width jumbotron without any corners. Defaults to false.

$options array

HTML attributes / options for the jumbotron container.

listGroup() public static method

Generates a list group. Flexible and powerful component for displaying not only simple lists of elements, but complex ones with custom content.

Example:

echo Html::listGroup([
   [
     'content' => 'Cras justo odio',
     'url' => '#',
     'badge' => '14',
     'active' => true
   ],
   [
     'content' => 'Dapibus ac facilisis in',
     'url' => '#',
     'badge' => '2'
   ],
   [
     'content' => 'Morbi leo risus',
     'url' => '#',
     'badge' => '1'
   ],
]);

echo Html::listGroup([
   [
     'content' => ['heading' => 'Heading 1', 'body' => 'Cras justo odio'],
     'url' => '#',
     'badge' => '14',
     'active' => true
   ],
   [
     'content' => ['heading' => 'Heading 2', 'body' => 'Dapibus ac facilisis in'],
     'url' => '#',
     'badge' => '2'
   ],
   [
     'content' => ['heading' => 'Heading 2', 'body' => 'Morbi leo risus'],
     'url' => '#',
     'badge' => '1'
   ],
]);

See also http://getbootstrap.com/components/#list-group.

public static string listGroup ( $items = [], $options = [], $itemOptions = [], $badgeOptions = [] )
$items array

The list group items. The following array key properties can be setup:

  • content: mixed, the list item content. When passed as a string, it will display this directly as a raw content. When passed as an array, it requires these keys
    • heading: string, the content heading (optional).
    • headingOptions: array, the HTML attributes / options for heading container (optional).
    • body: string, the content body (optional).
    • bodyOptions: array, the HTML attributes / options for body container (optional).
  • url: string|array, the url for linking the list item content (optional).
  • badge: string, any badge content to be displayed for this list item (optional)
  • badgeOptions: array, the HTML attributes / options for badge container (optional).
  • active: boolean, to highlight the item as active (applicable only if $url is passed). Defaults to false.
  • options: array, HTML attributes / options for the list group item container (optional). The following special option is recognized:
    • tag: string, the list group container tag. Defaults to 'div'.
$options array

HTML attributes for the list group container. The following special option is recognized:

  • tag: string, the list group container tag. Defaults to 'div'.
$itemOptions array

HTML attributes for the list group item options (will be overridden by options at the item level). The following special option is recognized:

  • tag: string, the list group container tag. Defaults to 'div'.
$badgeOptions array

HTML attributes for the list group item badge options (will be overridden by badgeOptions at the item level)

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

Generates a bootstrap media object. Abstract object styles for building various types of components (like blog comments, Tweets, etc) that feature a left-aligned or right-aligned image alongside textual content.

Example:

echo Html::media(
   'Media heading 1',
   'Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo.',
   '#',
   'http://placehold.it/64x64'
);

See also http://getbootstrap.com/components/#media.

public static string media ( $heading '', $body '', $src '', $img '', $srcOptions = [], $imgOptions = [], $headingOptions = [], $bodyOptions = [], $options = [], $tag 'div' )
$heading string

The media heading.

$body string

The media content.

$src string|array

URL for the media article source.

$img string|array

URL for the media image source.

$srcOptions array

Html options for the media article link.

$imgOptions array

Html options for the media image.

$headingOptions array

HTML attributes / options for the media object heading container.

$bodyOptions array

HTML attributes / options for the media object body container.

$options array

HTML attributes / options for the media object container.

$tag string

The media container tag. Defaults to 'div'.

throws Exception
mediaList() public static method

Generates bootstrap list of media (useful for comment threads or articles lists).

Example:

echo Html::mediaList([
  [
     'heading' => 'Media heading 1',
     'body' => 'Cras sit amet nibh libero, in gravida nulla. ' .
         'Nulla vel metus scelerisque ante sollicitudin commodo. '.
         'Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.',
     'src' => '#',
     'img' => 'http://placehold.it/64x64',
     'items' => [
         [
             'heading' => 'Media heading 1.1',
             'body' => 'Cras sit amet nibh libero, in gravida nulla. ' .
                 'Nulla vel metus scelerisque ante sollicitudin commodo. ' .
                 'Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.',
             'src' => '#',
             'img' => 'http://placehold.it/64x64'
         ],
         [
             'heading' => 'Media heading 1.2',
             'body' => 'Cras sit amet nibh libero, in gravida nulla. ' .
                 'Nulla vel metus scelerisque ante sollicitudin commodo. ' .
                 'Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.',
             'src' => '#',
             'img' => 'http://placehold.it/64x64'
         ],
     ]
  ],
  [
     'heading' => 'Media heading 2',
     'body' => 'Cras sit amet nibh libero, in gravida nulla. ' .
         'Nulla vel metus scelerisque ante sollicitudin commodo. ' .
         'Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.',
     'src' => '#',
     'img' => 'http://placehold.it/64x64'
  ],
]);

See also http://getbootstrap.com/components/#media.

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

The configuration of media items. Each item is an array consisting of following array keys:

  • items: array, the sub media items (similar in configuration to items) (optional)
  • heading: string, the media heading
  • body: string, the media content
  • src: mixed, URL for the media article source
  • img: mixed, URL for the media image source
  • srcOptions: array, HTML attributes / options for the media article link (optional)
  • imgOptions: array, HTML attributes / options for the media image (optional)
  • headingOptions: array, HTML attributes / options for the media heading (optional)
  • bodyOptions: array, HTML attributes / options for the media body (optional)
  • options: array, HTML attributes / options for each media item (optional)
$options array

HTML attributes / options for the media list object container.

throws Exception
pageHeader() public static method

Generates a page header.

Example:

echo Html::pageHeader(
   'Example page header',
   'Subtext for header'
);

See also http://getbootstrap.com/components/#page-header.

public static string pageHeader ( $title, $subTitle '', $options = [] )
$title string

The title to be shown

$subTitle string

The subtitle to be shown as subtext within the title

$options array

HTML attributes/ options for the page header

panel() public static method

Generates a panel for boxing content.

Example:

echo Html::panel([
   'heading' => 'Panel Title',
   'body' => 'Panel Content',
   'footer' => 'Panel Footer',
], Html::TYPE_PRIMARY);

See also http://getbootstrap.com/components/#panels.

public static string panel ( $content = [], $type 'default', $options = [], $prefix null )
$content array

The panel content configuration. The following properties can be setup:

  • preHeading: string, raw content that will be placed before heading (optional).
  • heading: string, the panel box heading (optional).
  • preBody: string, raw content that will be placed before $body (optional).
  • body: string, the panel body content - this will be wrapped in a "panel-body" container (optional).
  • postBody: string, raw content that will be placed after $body (optional).
  • footer: string, the panel box footer (optional).
  • postFooter: string, raw content that will be placed after $footer (optional).
  • headingTitle: boolean, whether to pre-style heading content with a '.panel-title' class. Defaults to false.
  • footerTitle: boolean, whether to pre-style footer content with a '.panel-title' class. Defaults to false.
$type string

The panel type which can be one of the bootstrap color modifier constants. Defaults to TYPE_DEFAULT.

$options array

HTML attributes / options for the panel container

$prefix string

The CSS prefix for panel type. Defaults to panel panel-.

throws Exception
radioButtonGroup() public static method

Generates a bootstrap radio button group. A radio button group is like a checkbox button group, except that it only allows single selection.

Example:

echo Html::radioButtonGroup('rdo', [1], [1 => 'Option 1', 2 => 'Option 2', 3 => 'Option 3']);

See also http://getbootstrap.com/javascript/#buttons-checkbox-radio.

public static string radioButtonGroup ( $name, $selection null, $items = [], $options = [] )
$name string

The name attribute of each radio.

$selection string|array

The selected value(s).

$items array

The data item used to generate the radios. The array keys are the radio values, while the array values are the corresponding labels.

$options array

Options (name => config) for the radio list container tag. The following options are specially handled:

  • tag: string, the tag name of the container element.
  • unselect: string, the value that should be submitted when none of the radio buttons is selected. By setting this option, a hidden input will be generated.
  • encode: boolean, whether to HTML-encode the radio button labels. Defaults to true. This option is ignored if item option is set.
  • separator: string, the HTML code that separates items.
  • itemOptions: array, the options for generating the radio button tag using radio().
  • item: Closure, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be:

    function ($index, $label, $name, $checked, $value)
    

    where $index is the zero-based index of the radio button in the whole list; $label is the label for the radio button; and $name, $value and $checked represent the name, value and the checked status of the radio button input.

See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated radio button group

well() public static method

Generates a well container.

See also http://getbootstrap.com/components/#wells.

public static string well ( $content, $size '', $options = [] )
$content string

The content

$size string

The well size. Should be one of the bootstrap size modifiers:

$options array

HTML attributes / options for the well container.

throws Exception