Class yii\helpers\BaseHtml

Inheritanceyii\helpers\BaseHtml
Subclassesyii\bootstrap\BaseHtml, yii\bootstrap\Html, yii\helpers\Html
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php

BaseHtml provides concrete implementation for yii\helpers\Html.

Do not use BaseHtml. Use yii\helpers\Html instead.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$attributeOrder array The preferred order of attributes in a tag. yii\helpers\BaseHtml
$dataAttributes array List of tag attributes that should be specially handled when their values are of array type. 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
activeCheckbox() Generates a checkbox tag together with a label for the given model attribute. yii\helpers\BaseHtml
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
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
beginForm() Generates a form start tag. yii\helpers\BaseHtml
beginTag() Generates a start tag. yii\helpers\BaseHtml
button() Generates a button tag. yii\helpers\BaseHtml
buttonInput() Generates an input button. yii\helpers\BaseHtml
checkbox() Generates a checkbox input. yii\helpers\BaseHtml
checkboxList() Generates a list of checkboxes. yii\helpers\BaseHtml
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
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
getInputId() Generates an appropriate input ID for the specified attribute name or expression. 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
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
label() Generates a label tag. yii\helpers\BaseHtml
listBox() Generates a list box. yii\helpers\BaseHtml
mailto() Generates a mailto hyperlink. yii\helpers\BaseHtml
ol() Generates an ordered list. yii\helpers\BaseHtml
passwordInput() Generates a password input field. yii\helpers\BaseHtml
radio() Generates a radio button input. yii\helpers\BaseHtml
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

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
activeListInput() Generates a list of input fields. yii\helpers\BaseHtml

Property Details

$attributeOrder public property
array $attributeOrder = ['type''id''class''name''value''href''src''action''method''selected''checked''readonly''disabled''multiple''size''maxlength''width''height''rows''cols''alt''title''rel''media']

The preferred order of attributes in a tag. This mainly affects the order of the attributes that are rendered by renderTagAttributes().

$dataAttributes public property (available since version 2.0.3)
array $dataAttributes = ['data''data-ng''ng']

List of tag attributes that should be specially handled when their values are of array type. In particular, if the value of the data attribute is ['name' => 'xyz', 'age' => 13], two attributes will be generated instead of one: data-name="xyz" data-age="13".

$voidElements public property
array $voidElements = ['area' => 1'base' => 1'br' => 1'col' => 1'command' => 1'embed' => 1'hr' => 1'img' => 1'input' => 1'keygen' => 1'link' => 1'meta' => 1'param' => 1'source' => 1'track' => 1'wbr' => 1]

List of void elements (element name => 1)

See also http://www.w3.org/TR/html-markup/syntax.html#void-element.

Method Details

a() public method

Generates a hyperlink tag.

See also yii\helpers\Url::to().

string a$text$url null$options = [] )
$text string

Link body. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is coming from end users, you should consider encode() it to prevent XSS attacks.

$url array|string|null

The URL for the hyperlink tag. This parameter will be processed by yii\helpers\Url::to() and will be used for the "href" attribute of the tag. If this parameter is null, the "href" attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated hyperlink

activeCheckbox() public method

Generates a checkbox tag together with a label for the given model attribute.

This method will generate the "checked" tag attribute according to the model attribute value.

string activeCheckbox$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • uncheck: string, the value associated with the uncheck state of the radio button. If not set, it will take the default value '0'. This method will render a hidden input so that if the radio button is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input. If you do not want any hidden input, you should explicitly set this option as null.
  • label: string, a label displayed next to the checkbox. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should encode() it to prevent XSS attacks. The checkbox will be enclosed by the label tag. Note that if you do not specify this option, a default label will be used based on the attribute label declaration in the model. If you do not want any label, you should explicitly set this option as null.
  • labelOptions: array, the HTML attributes for the label tag. This is only used when the "label" option is specified.

The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated checkbox tag

activeCheckboxList() public method

Generates a list of checkboxes.

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

string activeCheckboxList$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: callable, 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 list

activeDropDownList() public method

Generates a drop-down list for the given model attribute.

The selection of the drop-down list is taken from the value of the model attribute.

string activeDropDownList$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 option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using yii\helpers\ArrayHelper::map().

Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded.

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • prompt: string, a prompt text to be displayed as the first option;
  • options: array, the attributes for the select option tags. The array keys must be valid option values, and the array values are the extra attributes for the corresponding option tags. For example,

    [
        'value1' => ['disabled' => true],
        'value2' => ['label' => 'value 2'],
    ];
    
  • groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', except that the array keys represent the optgroup labels specified in $items.
  • encodeSpaces: bool, whether to encode spaces in option prompt and option value with   character. Defaults to false.
  • encode: bool, whether to encode option prompt and option value characters. Defaults to true. This option is available since 2.0.3.

The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated drop-down list tag

activeFileInput() public method

Generates a file input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.

string activeFileInput$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated input tag

activeHiddenInput() public method

Generates a hidden input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.

string activeHiddenInput$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated input tag

activeHint() public method (available since version 2.0.4)

Generates a hint tag for the given model attribute.

The hint text is the hint associated with the attribute, obtained via yii\base\Model::getAttributeHint(). If no hint content can be obtained, method will return an empty string.

string activeHint$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. The following options are specially handled:

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

return string

The generated hint tag

activeInput() public method

Generates an input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.

string activeInput$type$model$attribute$options = [] )
$type string

The input type (e.g. 'text', 'password')

$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated input tag

activeLabel() public method

Generates a label tag for the given model attribute.

The label text is the label associated with the attribute, obtained via yii\base\Model::getAttributeLabel().

string activeLabel$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. The following options are specially handled:

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

return string

The generated label tag

activeListBox() public method

Generates a list box.

The selection of the list box is taken from the value of the model attribute.

string activeListBox$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 option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using yii\helpers\ArrayHelper::map().

Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded.

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • prompt: string, a prompt text to be displayed as the first option;
  • options: array, the attributes for the select option tags. The array keys must be valid option values, and the array values are the extra attributes for the corresponding option tags. For example,

    [
        'value1' => ['disabled' => true],
        'value2' => ['label' => 'value 2'],
    ];
    
  • groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', except that the array keys represent the optgroup labels specified in $items.
  • unselect: string, the value that will be submitted when no option is selected. When this attribute is set, a hidden field will be generated so that if no option is selected in multiple mode, we can still obtain the posted unselect value.
  • encodeSpaces: bool, whether to encode spaces in option prompt and option value with   character. Defaults to false.
  • encode: bool, whether to encode option prompt and option value characters. Defaults to true. This option is available since 2.0.3.

The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated list box tag

activeListInput() protected method

Generates a list of input fields.

This method is mainly called by activeListBox(), activeRadioList() and \yii\helpers\activeCheckBoxList().

string activeListInput$type$model$attribute$items$options = [] )
$type string

The input type. This can be 'listBox', 'radioList', or 'checkBoxList'.

$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 input fields. The array keys are the input 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 input list. The supported special options depend on the input type specified by $type.

return string

The generated input list

activePasswordInput() public method

Generates a password input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.

string activePasswordInput$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). See renderTagAttributes() for details on how attributes are being rendered. The following special options are recognized:

  • maxlength: integer|boolean, when maxlength is set true and the model attribute is validated by a string validator, the maxlength option will take the value of yii\validators\StringValidator::$max. This is available since version 2.0.5.
return string

The generated input tag

activeRadio() public method

Generates a radio button tag together with a label for the given model attribute.

This method will generate the "checked" tag attribute according to the model attribute value.

string activeRadio$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • uncheck: string, the value associated with the uncheck state of the radio button. If not set, it will take the default value '0'. This method will render a hidden input so that if the radio button is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input. If you do not want any hidden input, you should explicitly set this option as null.
  • label: string, a label displayed next to the radio button. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should encode() it to prevent XSS attacks. The radio button will be enclosed by the label tag. Note that if you do not specify this option, a default label will be used based on the attribute label declaration in the model. If you do not want any label, you should explicitly set this option as null.
  • labelOptions: array, the HTML attributes for the label tag. This is only used when the "label" option is specified.

The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated radio button tag

activeRadioList() public method

Generates a list of radio buttons.

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

string activeRadioList$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. 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 radio button tag using radio().
  • item: callable, 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 list

activeTextInput() public method

Generates a text input tag for the given model attribute.

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.

string activeTextInput$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). See renderTagAttributes() for details on how attributes are being rendered. The following special options are recognized:

  • maxlength: integer|boolean, when maxlength is set true and the model attribute is validated by a string validator, the maxlength option will take the value of yii\validators\StringValidator::$max. This is available since version 2.0.3.
return string

The generated input tag

activeTextarea() public method

Generates a textarea tag for the given model attribute.

The model attribute value will be used as the content in the textarea.

string activeTextarea$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). See renderTagAttributes() for details on how attributes are being rendered. The following special options are recognized:

  • maxlength: integer|boolean, when maxlength is set true and the model attribute is validated by a string validator, the maxlength option will take the value of yii\validators\StringValidator::$max. This is available since version 2.0.5.
return string

The generated textarea tag

addCssClass() public method

Adds a CSS class (or several classes) to the specified options.

If the CSS class is already in the options, it will not be added again. If class specification at given options is an array, and some class placed there with the named (string) key, overriding of such key will have no effect. For example:

$options = ['class' => ['persistent' => 'initial']];
Html::addCssClass($options, ['persistent' => 'override']);
var_dump($options['class']); // outputs: array('persistent' => 'initial');
void addCssClass( <b>&</b>$options$class )
$options array

The options to be modified.

$class string|array

The CSS class(es) to be added

addCssStyle() public method

Adds the specified CSS style to the HTML options.

If the options already contain a style element, the new style will be merged with the existing one. If a CSS property exists in both the new and the old styles, the old one may be overwritten if $overwrite is true.

For example,

Html::addCssStyle($options'width: 100px; height: 200px');

See also:

void addCssStyle( <b>&</b>$options$style$overwrite true )
$options array

The HTML options to be modified.

$style string|array

The new style string (e.g. 'width: 100px; height: 200px') or array (e.g. ['width' => '100px', 'height' => '200px']).

$overwrite boolean

Whether to overwrite existing CSS properties if the new style contain them too.

beginForm() public method

Generates a form start tag.

See also endForm().

string beginForm$action ''$method 'post'$options = [] )
$action array|string

The form action URL. This parameter will be processed by yii\helpers\Url::to().

$method string

The form submission method, such as "post", "get", "put", "delete" (case-insensitive). Since most browsers only support "post" and "get", if other methods are given, they will be simulated using "post", and a hidden input will be added which contains the actual method type. See yii\web\Request::$methodParam for more details.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated form start tag.

beginTag() public method

Generates a start tag.

See also:

string beginTag$name$options = [] )
$name string

The tag name

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated start tag

button() public method

Generates a button tag.

string button$content 'Button'$options = [] )
$content string

The content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider encode() it to prevent XSS attacks.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated button tag

buttonInput() public method

Generates an input button.

string buttonInput$label 'Button'$options = [] )
$label string

The value attribute. If it is null, the value attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated button tag

checkbox() public method

Generates a checkbox input.

string checkbox$name$checked false$options = [] )
$name string

The name attribute.

$checked boolean

Whether the checkbox should be checked.

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • uncheck: string, the value associated with the uncheck state of the checkbox. When this attribute is present, a hidden input will be generated so that if the checkbox is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input.
  • label: string, a label displayed next to the checkbox. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should encode() it to prevent XSS attacks. When this option is specified, the checkbox will be enclosed by a label tag.
  • labelOptions: array, the HTML attributes for the label tag. Do not set this option unless you set the "label" option.

The rest of the options will be rendered as the attributes of the resulting checkbox tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated checkbox tag

checkboxList() public method

Generates a list of checkboxes.

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

string checkboxList$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. By setting this option, a hidden input will be generated.
  • 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: callable, 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, respectively.

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

return string

The generated checkbox list

csrfMetaTags() public method

Generates the meta tags containing CSRF token information.

See also yii\web\Request::$enableCsrfValidation.

string csrfMetaTags( )
return string

The generated meta tags

cssFile() public method

Generates a link tag that refers to an external CSS file.

See also yii\helpers\Url::to().

string cssFile$url$options = [] )
$url array|string

The URL of the external CSS file. This parameter will be processed by yii\helpers\Url::to().

$options array

The tag options in terms of name-value pairs. The following option is specially handled:

  • condition: specifies the conditional comments for IE, e.g., lt IE 9. When this is specified, the generated link tag will be enclosed within the conditional comments. This is mainly useful for supporting old versions of IE browsers.
  • noscript: if set to true, link tag will be wrapped into <noscript> tags.

The rest of the options will be rendered as the attributes of the resulting link tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated link tag

cssStyleFromArray() public method

Converts a CSS style array into a string representation.

For example,

print_r(Html::cssStyleFromArray(['width' => '100px''height' => '200px']));
// will display: 'width: 100px; height: 200px;'
string cssStyleFromArray( array $style )
$style array

The CSS style array. The array keys are the CSS property names, and the array values are the corresponding CSS property values.

return string

The CSS style string. If the CSS style is empty, a null will be returned.

cssStyleToArray() public method

Converts a CSS style string into an array representation.

The array keys are the CSS property names, and the array values are the corresponding CSS property values.

For example,

print_r(Html::cssStyleToArray('width: 100px; height: 200px;'));
// will display: ['width' => '100px', 'height' => '200px']
array cssStyleToArray$style )
$style string

The CSS style string

return array

The array representation of the CSS style

decode() public method

Decodes special HTML entities back to the corresponding characters.

This is the opposite of encode().

See also:

string decode$content )
$content string

The content to be decoded

return string

The decoded content

Generates a drop-down list.

string dropDownList$name$selection null$items = [], $options = [] )
$name string

The input name

$selection string

The selected value

$items array

The option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using yii\helpers\ArrayHelper::map().

Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded.

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • prompt: string, a prompt text to be displayed as the first option;
  • options: array, the attributes for the select option tags. The array keys must be valid option values, and the array values are the extra attributes for the corresponding option tags. For example,

    [
        'value1' => ['disabled' => true],
        'value2' => ['label' => 'value 2'],
    ];
    
  • groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', except that the array keys represent the optgroup labels specified in $items.
  • encodeSpaces: bool, whether to encode spaces in option prompt and option value with &nbsp; character. Defaults to false.
  • encode: bool, whether to encode option prompt and option value characters. Defaults to true. This option is available since 2.0.3.

The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated drop-down list tag

encode() public method

Encodes special characters into HTML entities.

The application charset will be used for encoding.

See also:

string encode$content$doubleEncode true )
$content string

The content to be encoded

$doubleEncode boolean

Whether to encode HTML entities in $content. If false, HTML entities in $content will not be further encoded.

return string

The encoded content

endForm() public method

Generates a form end tag.

See also beginForm().

string endForm( )
return string

The generated tag

endTag() public method

Generates an end tag.

See also:

string endTag$name )
$name string

The tag name

return string

The generated end tag

error() public method

Generates a tag that contains the first validation error of the specified model attribute.

Note that even if there is no validation error, this method will still return an empty error tag.

string error$model$attribute$options = [] )
$model yii\base\Model

The model object

$attribute string

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

$options array

The tag options in terms of name-value pairs. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered.

The following options are specially handled:

  • tag: this specifies the tag name. If not set, "div" will be used.
  • encode: boolean, if set to false then the error message won't be encoded.

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

return string

The generated label tag

errorSummary() public method

Generates a summary of the validation errors.

If there is no validation error, an empty error summary markup will still be generated, but it will be hidden.

string errorSummary$models$options = [] )
$models yii\base\Model|yii\base\Model[]

The model(s) whose validation errors are to be displayed

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • header: string, the header HTML for the error summary. If not set, a default prompt string will be used.
  • footer: string, the footer HTML for the error summary.
  • encode: boolean, if set to false then the error messages won't be encoded.

The rest of the options will be rendered as the attributes of the container tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered.

return string

The generated error summary

fileInput() public method

Generates a file input field.

To use a file input field, you should set the enclosing form's "enctype" attribute to be "multipart/form-data". After the form is submitted, the uploaded file information can be obtained via $_FILES[$name] (see PHP documentation).

string fileInput$name$value null$options = [] )
$name string

The name attribute.

$value string

The value attribute. If it is null, the value attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated file input tag

getAttributeName() public method

Returns the real attribute name from the given attribute expression.

An attribute expression is an attribute name prefixed and/or suffixed with array indexes. It is mainly used in tabular data input and/or input of array type. Below are some examples:

  • [0]content is used in tabular data input to represent the "content" attribute for the first model in tabular input;
  • dates[0] represents the first array element of the "dates" attribute;
  • [0]dates[0] represents the first array element of the "dates" attribute for the first model in tabular input.

If $attribute has neither prefix nor suffix, it will be returned back without change.

string getAttributeName$attribute )
$attribute string

The attribute name or expression

return string

The attribute name without prefix and suffix.

throws yii\base\InvalidParamException

if the attribute name contains non-word characters.

getAttributeValue() public method

Returns the value of the specified attribute name or expression.

For an attribute expression like [0]dates[0], this method will return the value of $model->dates[0]. See getAttributeName() for more details about attribute expression.

If an attribute value is an instance of yii\db\ActiveRecordInterface or an array of such instances, the primary value(s) of the AR instance(s) will be returned instead.

string|array getAttributeValue$model$attribute )
$model yii\base\Model

The model object

$attribute string

The attribute name or expression

return string|array

The corresponding attribute value

throws yii\base\InvalidParamException

if the attribute name contains non-word characters.

getInputId() public method

Generates an appropriate input ID for the specified attribute name or expression.

This method converts the result getInputName() into a valid input ID. For example, if getInputName() returns Post[content], this method will return post-content.

string getInputId$model$attribute )
$model yii\base\Model

The model object

$attribute string

The attribute name or expression. See getAttributeName() for explanation of attribute expression.

return string

The generated input ID

throws yii\base\InvalidParamException

if the attribute name contains non-word characters.

getInputName() public method

Generates an appropriate input name for the specified attribute name or expression.

This method generates a name that can be used as the input name to collect user input for the specified attribute. The name is generated according to the form name of the model and the given attribute name. For example, if the form name of the Post model is Post, then the input name generated for the content attribute would be Post[content].

See getAttributeName() for explanation of attribute expression.

string getInputName$model$attribute )
$model yii\base\Model

The model object

$attribute string

The attribute name or expression

return string

The generated input name

throws yii\base\InvalidParamException

if the attribute name contains non-word characters.

hiddenInput() public method

Generates a hidden input field.

string hiddenInput$name$value null$options = [] )
$name string

The name attribute.

$value string

The value attribute. If it is null, the value attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated hidden input tag

img() public method

Generates an image tag.

string img$src$options = [] )
$src array|string

The image URL. This parameter will be processed by yii\helpers\Url::to().

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated image tag

input() public method

Generates an input type of the given type.

string input$type$name null$value null$options = [] )
$type string

The type attribute.

$name string

The name attribute. If it is null, the name attribute will not be generated.

$value string

The value attribute. If it is null, the value attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated input tag

jsFile() public method

Generates a script tag that refers to an external JavaScript file.

See also yii\helpers\Url::to().

string jsFile$url$options = [] )
$url string

The URL of the external JavaScript file. This parameter will be processed by yii\helpers\Url::to().

$options array

The tag options in terms of name-value pairs. The following option is specially handled:

  • condition: specifies the conditional comments for IE, e.g., lt IE 9. When this is specified, the generated script tag will be enclosed within the conditional comments. This is mainly useful for supporting old versions of IE browsers.

The rest of the options will be rendered as the attributes of the resulting script tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated script tag

label() public method

Generates a label tag.

string label$content$for null$options = [] )
$content string

Label text. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should encode() it to prevent XSS attacks.

$for string

The ID of the HTML element that this label is associated with. If this is null, the "for" attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated label tag

listBox() public method

Generates a list box.

string listBox$name$selection null$items = [], $options = [] )
$name string

The input name

$selection string|array

The selected value(s)

$items array

The option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using yii\helpers\ArrayHelper::map().

Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded.

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • prompt: string, a prompt text to be displayed as the first option;
  • options: array, the attributes for the select option tags. The array keys must be valid option values, and the array values are the extra attributes for the corresponding option tags. For example,

    [
        'value1' => ['disabled' => true],
        'value2' => ['label' => 'value 2'],
    ];
    
  • groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options', except that the array keys represent the optgroup labels specified in $items.
  • unselect: string, the value that will be submitted when no option is selected. When this attribute is set, a hidden field will be generated so that if no option is selected in multiple mode, we can still obtain the posted unselect value.
  • encodeSpaces: bool, whether to encode spaces in option prompt and option value with &nbsp; character. Defaults to false.
  • encode: bool, whether to encode option prompt and option value characters. Defaults to true. This option is available since 2.0.3.

The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated list box tag

mailto() public method

Generates a mailto hyperlink.

string mailto$text$email null$options = [] )
$text string

Link body. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is coming from end users, you should consider encode() it to prevent XSS attacks.

$email string

Email address. If this is null, the first parameter (link body) will be treated as the email address and used.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated mailto link

ol() public method

Generates an ordered list.

string ol$items$options = [] )
$items array|Traversable

The items for generating the list. Each item generates a single list item. Note that items will be automatically HTML encoded if $options['encode'] is not set or true.

$options array

Options (name => config) for the radio button list. The following options are supported:

  • encode: boolean, whether to HTML-encode the items. Defaults to true. This option is ignored if the item option is specified.
  • itemOptions: array, the HTML attributes for the li tags. This option is ignored if the item option is specified.
  • item: callable, a callback that is used to generate each individual list item. The signature of this callback must be:

    function ($item, $index)
    

    where $index is the array key corresponding to $item in $items. The callback should return the whole list item tag.

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

return string

The generated ordered list. An empty string is returned if $items is empty.

passwordInput() public method

Generates a password input field.

string passwordInput$name$value null$options = [] )
$name string

The name attribute.

$value string

The value attribute. If it is null, the value attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated password input tag

radio() public method

Generates a radio button input.

string radio$name$checked false$options = [] )
$name string

The name attribute.

$checked boolean

Whether the radio button should be checked.

$options array

The tag options in terms of name-value pairs. The following options are specially handled:

  • uncheck: string, the value associated with the uncheck state of the radio button. When this attribute is present, a hidden input will be generated so that if the radio button is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input.
  • label: string, a label displayed next to the radio button. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should encode() it to prevent XSS attacks. When this option is specified, the radio button will be enclosed by a label tag.
  • labelOptions: array, the HTML attributes for the label tag. Do not set this option unless you set the "label" option.

The rest of the options will be rendered as the attributes of the resulting radio button tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated radio button tag

radioList() public method

Generates a list of radio buttons.

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

string radioList$name$selection null$items = [], $options = [] )
$name string

The name attribute of each radio button.

$selection string|array

The selected value(s).

$items array

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

$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 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 radio button tag using radio().
  • item: callable, 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, respectively.

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

return string

The generated radio button list

removeCssClass() public method

Removes a CSS class from the specified options.

void removeCssClass( <b>&</b>$options$class )
$options array

The options to be modified.

$class string|array

The CSS class(es) to be removed

removeCssStyle() public method

Removes the specified CSS style from the HTML options.

For example,

Html::removeCssStyle($options, ['width''height']);

See also addCssStyle().

void removeCssStyle( <b>&</b>$options$properties )
$options array

The HTML options to be modified.

$properties string|array

The CSS properties to be removed. You may use a string if you are removing a single property.

renderSelectOptions() public method

Renders the option tags that can be used by dropDownList() and listBox().

string renderSelectOptions$selection$items, <b>&</b>$tagOptions = [] )
$selection string|array

The selected value(s). This can be either a string for single selection or an array for multiple selections.

$items array

The option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using yii\helpers\ArrayHelper::map().

Note, the values and labels will be automatically HTML-encoded by this method, and the blank spaces in the labels will also be HTML-encoded.

$tagOptions array

The $options parameter that is passed to the dropDownList() or listBox() call. This method will take out these elements, if any: "prompt", "options" and "groups". See more details in dropDownList() for the explanation of these elements.

return string

The generated list options

renderTagAttributes() public method

Renders the HTML tag attributes.

Attributes whose values are of boolean type will be treated as boolean attributes.

Attributes whose values are null will not be rendered.

The values of attributes will be HTML-encoded using encode().

The "data" attribute is specially handled when it is receiving an array value. In this case, the array will be "expanded" and a list data attributes will be rendered. For example, if 'data' => ['id' => 1, 'name' => 'yii'], then this will be rendered: data-id="1" data-name="yii". Additionally 'data' => ['params' => ['id' => 1, 'name' => 'yii'], 'status' => 'ok'] will be rendered as: data-params='{"id":1,"name":"yii"}' data-status="ok".

string renderTagAttributes$attributes )
$attributes array

Attributes to be rendered. The attribute values will be HTML-encoded using encode().

return string

The rendering result. If the attributes are not empty, they will be rendered into a string with a leading white space (so that it can be directly appended to the tag name in a tag. If there is no attribute, an empty string will be returned.

resetButton() public method

Generates a reset button tag.

string resetButton$content 'Reset'$options = [] )
$content string

The content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider encode() it to prevent XSS attacks.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated reset button tag

resetInput() public method

Generates a reset input button.

string resetInput$label 'Reset'$options = [] )
$label string

The value attribute. If it is null, the value attribute will not be generated.

$options array

The attributes of the button tag. The values will be HTML-encoded using encode(). Attributes whose value is null will be ignored and not put in the tag returned. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated button tag

script() public method

Generates a script tag.

string script$content$options = [] )
$content string

The script content

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated script tag

style() public method

Generates a style tag.

string style$content$options = [] )
$content string

The style content

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated style tag

submitButton() public method

Generates a submit button tag.

string submitButton$content 'Submit'$options = [] )
$content string

The content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider encode() it to prevent XSS attacks.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated submit button tag

submitInput() public method

Generates a submit input button.

string submitInput$label 'Submit'$options = [] )
$label string

The value attribute. If it is null, the value attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated button tag

tag() public method

Generates a complete HTML tag.

See also:

string tag$name$content ''$options = [] )
$name string

The tag name

$content string

The content to be enclosed between the start and end tags. It will not be HTML-encoded. If this is coming from end users, you should consider encode() it to prevent XSS attacks.

$options array

The HTML tag attributes (HTML options) in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered.

For example when using ['class' => 'my-class', 'target' => '_blank', 'value' => null] it will result in the html attributes rendered like this: class="my-class" target="_blank".

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

return string

The generated HTML tag

textInput() public method

Generates a text input field.

string textInput$name$value null$options = [] )
$name string

The name attribute.

$value string

The value attribute. If it is null, the value attribute will not be generated.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated text input tag

textarea() public method

Generates a text area input.

string textarea$name$value ''$options = [] )
$name string

The input name

$value string

The input value. Note that it will be encoded using encode().

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using encode(). If a value is null, the corresponding attribute will not be rendered. See renderTagAttributes() for details on how attributes are being rendered.

return string

The generated text area tag

ul() public method

Generates an unordered list.

string ul$items$options = [] )
$items array|Traversable

The items for generating the list. Each item generates a single list item. Note that items will be automatically HTML encoded if $options['encode'] is not set or true.

$options array

Options (name => config) for the radio button list. The following options are supported:

  • encode: boolean, whether to HTML-encode the items. Defaults to true. This option is ignored if the item option is specified.
  • itemOptions: array, the HTML attributes for the li tags. This option is ignored if the item option is specified.
  • item: callable, a callback that is used to generate each individual list item. The signature of this callback must be:

    function ($item, $index)
    

    where $index is the array key corresponding to $item in $items. The callback should return the whole list item tag.

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

return string

The generated unordered list. An empty list tag will be returned if $items is empty.