PHP Class yii\helpers\BaseHtml

Do not use BaseHtml. Use [[Html]] instead.
Since: 2.0
Author: Qiang Xue ([email protected])
Datei anzeigen Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$attributeOrder the preferred order of attributes in a tag. This mainly affects the order of the attributes that are rendered by BaseHtml::renderTagAttributes.
$dataAttributes 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 list of void elements (element name => 1)

Public Methods

Method Description
a ( string $text, array | string | null $url = null, array $options = [] ) : string Generates a hyperlink tag.
activeCheckbox ( Model $model, string $attribute, array $options = [] ) : string Generates a checkbox tag together with a label for the given model attribute.
activeCheckboxList ( Model $model, string $attribute, array $items, array $options = [] ) : string Generates a list of checkboxes.
activeDropDownList ( Model $model, string $attribute, array $items, array $options = [] ) : string Generates a drop-down list for the given model attribute.
activeFileInput ( Model $model, string $attribute, array $options = [] ) : string Generates a file input tag for the given model attribute.
activeHiddenInput ( Model $model, string $attribute, array $options = [] ) : string Generates a hidden input tag for the given model attribute.
activeHint ( Model $model, string $attribute, array $options = [] ) : string Generates a hint tag for the given model attribute.
activeInput ( string $type, Model $model, string $attribute, array $options = [] ) : string Generates an input tag for the given model attribute.
activeLabel ( Model $model, string $attribute, array $options = [] ) : string Generates a label tag for the given model attribute.
activeListBox ( Model $model, string $attribute, array $items, array $options = [] ) : string Generates a list box.
activePasswordInput ( Model $model, string $attribute, array $options = [] ) : string Generates a password input tag for the given model attribute.
activeRadio ( Model $model, string $attribute, array $options = [] ) : string Generates a radio button tag together with a label for the given model attribute.
activeRadioList ( Model $model, string $attribute, array $items, array $options = [] ) : string Generates a list of radio buttons.
activeTextInput ( Model $model, string $attribute, array $options = [] ) : string Generates a text input tag for the given model attribute.
activeTextarea ( Model $model, string $attribute, array $options = [] ) : string Generates a textarea tag for the given model attribute.
addCssClass ( array &$options, string | array $class ) Adds a CSS class (or several classes) to the specified options.
addCssStyle ( array &$options, string | array $style, boolean $overwrite = true ) Adds the specified CSS style to the HTML options.
beginForm ( array | string $action = '', string $method = 'post', array $options = [] ) : string Generates a form start tag.
beginTag ( string | boolean | null $name, array $options = [] ) : string Generates a start tag.
button ( string $content = 'Button', array $options = [] ) : string Generates a button tag.
buttonInput ( string $label = 'Button', array $options = [] ) : string Generates an input button.
checkbox ( string $name, boolean $checked = false, array $options = [] ) : string Generates a checkbox input.
checkboxList ( string $name, string | array | null $selection = null, array $items = [], array $options = [] ) : string Generates a list of checkboxes.
csrfMetaTags ( ) : string Generates the meta tags containing CSRF token information.
cssFile ( array | string $url, array $options = [] ) : string Generates a link tag that refers to an external CSS file.
cssStyleFromArray ( array $style ) : string Converts a CSS style array into a string representation.
cssStyleToArray ( string $style ) : array Converts a CSS style string into an array representation.
decode ( string $content ) : string Decodes special HTML entities back to the corresponding characters.
dropDownList ( string $name, string | array | null $selection = null, array $items = [], array $options = [] ) : string Generates a drop-down list.
encode ( string $content, boolean $doubleEncode = true ) : string Encodes special characters into HTML entities.
endForm ( ) : string Generates a form end tag.
endTag ( string | boolean | null $name ) : string Generates an end tag.
error ( Model $model, string $attribute, array $options = [] ) : string Generates a tag that contains the first validation error of the specified model attribute.
errorSummary ( Model | Model[] $models, array $options = [] ) : string Generates a summary of the validation errors.
escapeJsRegularExpression ( string $regexp ) : string Escapes regular expression to use in JavaScript
fileInput ( string $name, string $value = null, array $options = [] ) : string Generates a file input field.
getAttributeName ( string $attribute ) : string Returns the real attribute name from the given attribute expression.
getAttributeValue ( Model $model, string $attribute ) : string | array Returns the value of the specified attribute name or expression.
getInputId ( Model $model, string $attribute ) : string Generates an appropriate input ID for the specified attribute name or expression.
getInputName ( Model $model, string $attribute ) : string Generates an appropriate input name for the specified attribute name or expression.
hiddenInput ( string $name, string $value = null, array $options = [] ) : string Generates a hidden input field.
img ( array | string $src, array $options = [] ) : string Generates an image tag.
input ( string $type, string $name = null, string $value = null, array $options = [] ) : string Generates an input type of the given type.
jsFile ( string $url, array $options = [] ) : string Generates a script tag that refers to an external JavaScript file.
label ( string $content, string $for = null, array $options = [] ) : string Generates a label tag.
listBox ( string $name, string | array | null $selection = null, array $items = [], array $options = [] ) : string Generates a list box.
mailto ( string $text, string $email = null, array $options = [] ) : string Generates a mailto hyperlink.
ol ( array | Traversable $items, array $options = [] ) : string Generates an ordered list.
passwordInput ( string $name, string $value = null, array $options = [] ) : string Generates a password input field.
radio ( string $name, boolean $checked = false, array $options = [] ) : string Generates a radio button input.
radioList ( string $name, string | array | null $selection = null, array $items = [], array $options = [] ) : string Generates a list of radio buttons.
removeCssClass ( array &$options, string | array $class ) Removes a CSS class from the specified options.
removeCssStyle ( array &$options, string | array $properties ) Removes the specified CSS style from the HTML options.
renderSelectOptions ( string | array | null $selection, array $items, array &$tagOptions = [] ) : string Renders the option tags that can be used by BaseHtml::dropDownList and BaseHtml::listBox.
renderTagAttributes ( array $attributes ) : string Renders the HTML tag attributes.
resetButton ( string $content = 'Reset', array $options = [] ) : string Generates a reset button tag.
resetInput ( string $label = 'Reset', array $options = [] ) : string Generates a reset input button.
script ( string $content, array $options = [] ) : string Generates a script tag.
style ( string $content, array $options = [] ) : string Generates a style tag.
submitButton ( string $content = 'Submit', array $options = [] ) : string Generates a submit button tag.
submitInput ( string $label = 'Submit', array $options = [] ) : string Generates a submit input button.
tag ( string | boolean | null $name, string $content = '', array $options = [] ) : string Generates a complete HTML tag.
textInput ( string $name, string $value = null, array $options = [] ) : string Generates a text input field.
textarea ( string $name, string $value = '', array $options = [] ) : string Generates a text area input.
ul ( array | Traversable $items, array $options = [] ) : string Generates an unordered list.

Protected Methods

Method Description
activeBooleanInput ( string $type, Model $model, string $attribute, array $options = [] ) : string Generates a boolean input This method is mainly called by BaseHtml::activeCheckbox and BaseHtml::activeRadio.
activeListInput ( string $type, Model $model, string $attribute, array $items, array $options = [] ) : string Generates a list of input fields.
booleanInput ( string $type, string $name, boolean $checked = false, array $options = [] ) : string Generates a boolean input.

Private Methods

Method Description
mergeCssClasses ( array $existingClasses, array $additionalClasses ) : array Merges already existing CSS classes with new one.
normalizeMaxLength ( Model $model, string $attribute, array &$options ) If maxlength option 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]].
wrapIntoCondition ( string $content, string $condition ) : string Wraps given content into conditional comments for IE, e.g., lt IE 9.

Method Details

a() public static method

Generates a hyperlink tag.
See also: yii\helpers\Url::to()
public static a ( string $text, array | string | null $url = null, array $options = [] ) : string
$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 [[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. If you want to use an absolute url you can call [[Url::to()]] yourself, before passing the URL to this method, like this: ```php Html::a('link text', Url::to($url, true)) ```
$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

activeBooleanInput() protected static method

Generates a boolean input This method is mainly called by BaseHtml::activeCheckbox and BaseHtml::activeRadio.
Since: 2.0.9
protected static activeBooleanInput ( string $type, Model $model, string $attribute, array $options = [] ) : string
$type string the input type. This can be either `radio` or `checkbox`.
$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. See [[booleanInput()]] for details about accepted attributes.
return string the generated input element

activeCheckbox() public static method

This method will generate the "checked" tag attribute according to the model attribute value.
public static activeCheckbox ( Model $model, string $attribute, array $options = [] ) : string
$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. See [[booleanInput()]] for details about accepted attributes.
return string the generated checkbox tag

activeCheckboxList() public static method

A checkbox list allows multiple selection, like BaseHtml::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.
public static activeCheckboxList ( Model $model, string $attribute, array $items, array $options = [] ) : string
$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|false, the tag name of the container element. False to render checkbox without container. See also [[tag()]]. - 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: ```php 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 static method

The selection of the drop-down list is taken from the value of the model attribute.
public static activeDropDownList ( Model $model, string $attribute, array $items, array $options = [] ) : string
$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. Since version 2.0.11 you can use an array to override the value and to set other tag attributes: ```php ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']], ``` - 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, ```php [ '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 static method

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.
public static activeFileInput ( Model $model, string $attribute, array $options = [] ) : string
$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 static method

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.
public static activeHiddenInput ( Model $model, string $attribute, array $options = [] ) : string
$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 static method

The hint text is the hint associated with the attribute, obtained via [[Model::getAttributeHint()]]. If no hint content can be obtained, method will return an empty string.
Since: 2.0.4
public static activeHint ( Model $model, string $attribute, array $options = [] ) : string
$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: - hint: this specifies the hint to be displayed. Note that this will NOT be [[encode()|encoded]]. If this is not set, [[Model::getAttributeHint()]] will be called to get the hint for display (without encoding). See [[renderTagAttributes()]] for details on how attributes are being rendered.
return string the generated hint tag

activeInput() public static method

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.
public static activeInput ( string $type, Model $model, string $attribute, array $options = [] ) : string
$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 static method

The label text is the label associated with the attribute, obtained via [[Model::getAttributeLabel()]].
public static activeLabel ( Model $model, string $attribute, array $options = [] ) : string
$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: - label: this specifies the label to be displayed. Note that this will NOT be [[encode()|encoded]]. If this is not set, [[Model::getAttributeLabel()]] will be called to get the label for display (after encoding). See [[renderTagAttributes()]] for details on how attributes are being rendered.
return string the generated label tag

activeListBox() public static method

The selection of the list box is taken from the value of the model attribute.
public static activeListBox ( Model $model, string $attribute, array $items, array $options = [] ) : string
$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. Since version 2.0.11 you can use an array to override the value and to set other tag attributes: ```php ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']], ``` - 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, ```php [ '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 static method

protected static activeListInput ( string $type, Model $model, string $attribute, array $items, array $options = [] ) : string
$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 static method

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.
public static activePasswordInput ( Model $model, string $attribute, array $options = [] ) : string
$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 option is available since version 2.0.6.
return string the generated input tag

activeRadio() public static method

This method will generate the "checked" tag attribute according to the model attribute value.
public static activeRadio ( Model $model, string $attribute, array $options = [] ) : string
$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. See [[booleanInput()]] for details about accepted attributes.
return string the generated radio button tag

activeRadioList() public static method

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.
public static activeRadioList ( Model $model, string $attribute, array $items, array $options = [] ) : string
$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|false, the tag name of the container element. False to render radio button without container. See also [[tag()]]. - 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: ```php 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 static method

This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in $options.
public static activeTextInput ( Model $model, string $attribute, array $options = [] ) : string
$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 static method

The model attribute value will be used as the content in the textarea.
public static activeTextarea ( Model $model, string $attribute, array $options = [] ) : string
$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 option is available since version 2.0.6.
return string the generated textarea tag

addCssClass() public static method

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: php $options = ['class' => ['persistent' => 'initial']]; Html::addCssClass($options, ['persistent' => 'override']); var_dump($options['class']); // outputs: array('persistent' => 'initial');
public static addCssClass ( array &$options, string | array $class )
$options array the options to be modified.
$class string | array the CSS class(es) to be added

addCssStyle() public static method

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, php Html::addCssStyle($options, 'width: 100px; height: 200px');
See also: removeCssStyle()
See also: cssStyleFromArray()
See also: cssStyleToArray()
public static addCssStyle ( array &$options, string | array $style, boolean $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 static method

Generates a form start tag.
See also: endForm()
public static beginForm ( array | string $action = '', string $method = 'post', array $options = [] ) : string
$action array | string the form action URL. This parameter will be processed by [[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. Special options: - `csrf`: whether to generate the CSRF hidden input. Defaults to true.
return string the generated form start tag.

beginTag() public static method

Generates a start tag.
See also: endTag()
See also: tag()
public static beginTag ( string | boolean | null $name, array $options = [] ) : string
$name string | boolean | null the tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag.
$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

booleanInput() protected static method

Generates a boolean input.
Since: 2.0.9
protected static booleanInput ( string $type, string $name, boolean $checked = false, array $options = [] ) : string
$type string the input type. This can be either `radio` or `checkbox`.
$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

button() public static method

Generates a button tag.
public static button ( string $content = 'Button', array $options = [] ) : string
$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 static method

Generates an input button.
public static buttonInput ( string $label = 'Button', array $options = [] ) : string
$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 static method

Generates a checkbox input.
public static checkbox ( string $name, boolean $checked = false, array $options = [] ) : string
$name string the name attribute.
$checked boolean whether the checkbox should be checked.
$options array the tag options in terms of name-value pairs. See [[booleanInput()]] for details about accepted attributes.
return string the generated checkbox tag

checkboxList() public static method

A checkbox list allows multiple selection, like BaseHtml::listBox. As a result, the corresponding submitted value is an array.
public static checkboxList ( string $name, string | array | null $selection = null, array $items = [], array $options = [] ) : string
$name string the name attribute of each checkbox.
$selection string | array | null the selected value(s). String for single or array for multiple selection(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|false, the tag name of the container element. False to render checkbox without container. See also [[tag()]]. - 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: ```php 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 static method

Generates the meta tags containing CSRF token information.
See also: Request::enableCsrfValidation
public static csrfMetaTags ( ) : string
return string the generated meta tags

cssFile() public static method

Generates a link tag that refers to an external CSS file.
See also: Url::to()
public static cssFile ( array | string $url, array $options = [] ) : string
$url array | string the URL of the external CSS file. This parameter will be processed by [[Url::to()]].
$options array the tag options in terms of name-value pairs. The following options are 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 `
return string the generated link tag

cssStyleFromArray() public static method

For example, php print_r(Html::cssStyleFromArray(['width' => '100px', 'height' => '200px'])); will display: 'width: 100px; height: 200px;'
public static cssStyleFromArray ( array $style ) : string
$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 static method

The array keys are the CSS property names, and the array values are the corresponding CSS property values. For example, php print_r(Html::cssStyleToArray('width: 100px; height: 200px;')); will display: ['width' => '100px', 'height' => '200px']
public static cssStyleToArray ( string $style ) : array
$style string the CSS style string
return array the array representation of the CSS style

decode() public static method

This is the opposite of BaseHtml::encode.
See also: encode()
See also: http://www.php.net/manual/en/function.htmlspecialchars-decode.php
public static decode ( string $content ) : string
$content string the content to be decoded
return string the decoded content

dropDownList() public static method

Generates a drop-down list.
public static dropDownList ( string $name, string | array | null $selection = null, array $items = [], array $options = [] ) : string
$name string the input name
$selection string | array | null the selected value(s). String for single or array for multiple selection(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. Since version 2.0.11 you can use an array to override the value and to set other tag attributes: ```php ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']], ``` - 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, ```php [ '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

encode() public static method

The [[\yii\base\Application::charset|application charset]] will be used for encoding.
See also: decode()
See also: http://www.php.net/manual/en/function.htmlspecialchars.php
public static encode ( string $content, boolean $doubleEncode = true ) : string
$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 static method

Generates a form end tag.
See also: beginForm()
public static endForm ( ) : string
return string the generated tag

endTag() public static method

Generates an end tag.
See also: beginTag()
See also: tag()
public static endTag ( string | boolean | null $name ) : string
$name string | boolean | null the tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag.
return string the generated end tag

error() public static method

Note that even if there is no validation error, this method will still return an empty error tag.
public static error ( Model $model, string $attribute, array $options = [] ) : string
$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. See also [[tag()]]. - 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 static method

If there is no validation error, an empty error summary markup will still be generated, but it will be hidden.
public static errorSummary ( Model | Model[] $models, array $options = [] ) : string
$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. Defaults to empty string. - encode: boolean, if set to false then the error messages won't be encoded. Defaults to `true`. - showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise only the first error message for each attribute will be shown. Defaults to `false`. Option is available since 2.0.10. The rest of the options will be rendered as the attributes of the container tag.
return string the generated error summary

escapeJsRegularExpression() public static method

Escapes regular expression to use in JavaScript
Since: 2.0.6
public static escapeJsRegularExpression ( string $regexp ) : string
$regexp string the regular expression to be escaped.
return string the escaped result.

fileInput() public static method

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).
public static fileInput ( string $name, string $value = null, array $options = [] ) : string
$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 static method

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.
public static getAttributeName ( string $attribute ) : string
$attribute string the attribute name or expression
return string the attribute name without prefix and suffix.

getAttributeValue() public static method

For an attribute expression like [0]dates[0], this method will return the value of $model->dates[0]. See BaseHtml::getAttributeName for more details about attribute expression. If an attribute value is an instance of [[ActiveRecordInterface]] or an array of such instances, the primary value(s) of the AR instance(s) will be returned instead.
public static getAttributeValue ( Model $model, string $attribute ) : string | array
$model yii\base\Model the model object
$attribute string the attribute name or expression
return string | array the corresponding attribute value

getInputId() public static method

This method converts the result BaseHtml::getInputName into a valid input ID. For example, if BaseHtml::getInputName returns Post[content], this method will return post-content.
public static getInputId ( Model $model, string $attribute ) : string
$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

getInputName() public static method

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 [[Model::formName|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 BaseHtml::getAttributeName for explanation of attribute expression.
public static getInputName ( Model $model, string $attribute ) : string
$model yii\base\Model the model object
$attribute string the attribute name or expression
return string the generated input name

hiddenInput() public static method

Generates a hidden input field.
public static hiddenInput ( string $name, string $value = null, array $options = [] ) : string
$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 static method

Generates an image tag.
public static img ( array | string $src, array $options = [] ) : string
$src array | string the image URL. This parameter will be processed by [[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 static method

Generates an input type of the given type.
public static input ( string $type, string $name = null, string $value = null, array $options = [] ) : string
$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 static method

Generates a script tag that refers to an external JavaScript file.
See also: Url::to()
public static jsFile ( string $url, array $options = [] ) : string
$url string the URL of the external JavaScript file. This parameter will be processed by [[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 static method

Generates a label tag.
public static label ( string $content, string $for = null, array $options = [] ) : string
$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 static method

Generates a list box.
public static listBox ( string $name, string | array | null $selection = null, array $items = [], array $options = [] ) : string
$name string the input name
$selection string | array | null the selected value(s). String for single or array for multiple selection(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. Since version 2.0.11 you can use an array to override the value and to set other tag attributes: ```php ['text' => 'Please select', 'options' => ['value' => 'none', 'class' => 'prompt', 'label' => 'Select']], ``` - 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, ```php [ '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

mailto() public static method

Generates a mailto hyperlink.
public static mailto ( string $text, string $email = null, array $options = [] ) : string
$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 static method

Generates an ordered list.
public static ol ( array | Traversable $items, array $options = [] ) : string
$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: ```php 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 static method

Generates a password input field.
public static passwordInput ( string $name, string $value = null, array $options = [] ) : string
$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 static method

Generates a radio button input.
public static radio ( string $name, boolean $checked = false, array $options = [] ) : string
$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. See [[booleanInput()]] for details about accepted attributes.
return string the generated radio button tag

radioList() public static method

A radio button list is like a checkbox list, except that it only allows single selection.
public static radioList ( string $name, string | array | null $selection = null, array $items = [], array $options = [] ) : string
$name string the name attribute of each radio button.
$selection string | array | null the selected value(s). String for single or array for multiple selection(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|false, the tag name of the container element. False to render radio buttons without container. See also [[tag()]]. - 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: ```php 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 static method

Removes a CSS class from the specified options.
public static removeCssClass ( array &$options, string | array $class )
$options array the options to be modified.
$class string | array the CSS class(es) to be removed

removeCssStyle() public static method

For example, php Html::removeCssStyle($options, ['width', 'height']);
See also: addCssStyle()
public static removeCssStyle ( array &$options, string | array $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 static method

Renders the option tags that can be used by BaseHtml::dropDownList and BaseHtml::listBox.
public static renderSelectOptions ( string | array | null $selection, array $items, array &$tagOptions = [] ) : string
$selection string | array | null the selected value(s). String for single or array for multiple selection(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.
$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 static method

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 BaseHtml::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".
public static renderTagAttributes ( array $attributes ) : string
$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 static method

Generates a reset button tag.
public static resetButton ( string $content = 'Reset', array $options = [] ) : string
$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 static method

Generates a reset input button.
public static resetInput ( string $label = 'Reset', array $options = [] ) : string
$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 static method

Generates a script tag.
public static script ( string $content, array $options = [] ) : string
$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 static method

Generates a style tag.
public static style ( string $content, array $options = [] ) : string
$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 static method

Be careful when naming form elements such as submit buttons. According to the jQuery documentation there are some reserved names that can cause conflicts, e.g. submit, length, or method.
public static submitButton ( string $content = 'Submit', array $options = [] ) : string
$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 static method

Be careful when naming form elements such as submit buttons. According to the jQuery documentation there are some reserved names that can cause conflicts, e.g. submit, length, or method.
public static submitInput ( string $label = 'Submit', array $options = [] ) : string
$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 static method

Generates a complete HTML tag.
See also: beginTag()
See also: endTag()
public static tag ( string | boolean | null $name, string $content = '', array $options = [] ) : string
$name string | boolean | null the tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag.
$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 static method

Generates a text input field.
public static textInput ( string $name, string $value = null, array $options = [] ) : string
$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 static method

Generates a text area input.
public static textarea ( string $name, string $value = '', array $options = [] ) : string
$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. The following special options are recognized: - `doubleEncode`: whether to double encode HTML entities in `$value`. If `false`, HTML entities in `$value` will not be further encoded. This option is available since version 2.0.11.
return string the generated text area tag

ul() public static method

Generates an unordered list.
public static ul ( array | Traversable $items, array $options = [] ) : string
$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. - separator: string, the HTML code that separates items. Defaults to a simple newline (`"\n"`). This option is available since version 2.0.7. - 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: ```php 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.

Property Details

$attributeOrder public_oe static_oe property

the preferred order of attributes in a tag. This mainly affects the order of the attributes that are rendered by BaseHtml::renderTagAttributes.
public static $attributeOrder

$dataAttributes public_oe static_oe property

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".
Since: 2.0.3
public static $dataAttributes

$voidElements public_oe static_oe property

list of void elements (element name => 1)
See also: http://www.w3.org/TR/html-markup/syntax.html#void-element
public static $voidElements