Class yii\bootstrap4\BaseHtml

Inheritanceyii\bootstrap4\BaseHtml » yii\helpers\Html » yii\helpers\BaseHtml
Subclassesyii\bootstrap4\Html
Source Code https://github.com/yiisoft/yii2/blob/master/framework/bootstrap4/BaseHtml.php

BaseHtml provides concrete implementation for yii\bootstrap4\Html.

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

Public Properties

Hide inherited properties

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

Public Methods

Hide inherited methods

MethodDescriptionDefined By
a() Generates a hyperlink tag. yii\helpers\BaseHtml
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
activeStaticControl() Generates a Bootstrap static form control for the given model attribute. yii\bootstrap4\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\bootstrap4\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\bootstrap4\BaseHtml
errorSummary() Generates a summary of the validation errors. yii\helpers\BaseHtml
escapeJsRegularExpression() Escapes regular expression to use in JavaScript. yii\helpers\BaseHtml
fileInput() Generates a file input field. yii\helpers\BaseHtml
getAttributeName() Returns the real attribute name from the given attribute expression. yii\helpers\BaseHtml
getAttributeValue() Returns the value of the specified attribute name or expression. yii\helpers\BaseHtml
getInputId() Generates an appropriate input ID for the specified attribute name or expression. yii\helpers\BaseHtml
getInputIdByName() Converts input name to ID. yii\helpers\BaseHtml
getInputName() Generates an appropriate input name for the specified attribute name or expression. yii\helpers\BaseHtml
hiddenInput() Generates a hidden input field. yii\helpers\BaseHtml
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\bootstrap4\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
staticControl() Renders Bootstrap static form control. yii\bootstrap4\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
activeBooleanInput() Generates a boolean input This method is mainly called by activeCheckbox() and activeRadio(). yii\helpers\BaseHtml
activeListInput() Generates a list of input fields. yii\helpers\BaseHtml
booleanInput() Generates a boolean input. yii\bootstrap4\BaseHtml
getId() Returns an autogenerated ID yii\bootstrap4\BaseHtml
setActivePlaceholder() Generate placeholder from model attribute label. yii\helpers\BaseHtml

Property Details

$autoIdPrefix public static property

The prefix to the automatically generated widget IDs.

See also getId().

public static string $autoIdPrefix 'i'
$counter public static property

A counter used to generate id for widgets.

public static integer $counter 0
$dataAttributes public static property (available since version 2.0.3)

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".

public static array $dataAttributes = [
    'data''data-ng''ng''aria'
]

Method Details

activeStaticControl() public static method

Generates a Bootstrap static form control for the given model attribute.

See also staticControl().

public static string activeStaticControl ( $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. See staticControl() for details.

return string

Generated HTML

booleanInput() protected static method (available since version 2.0.9)

Generates a boolean input.

protected static string booleanInput ( $type, $name, $checked false, $options = [] )
$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

checkboxList() public static method

Generates a list of checkboxes.

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

public static string checkboxList ( $name, $selection null, $items = [], $options = [] )
$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.
  • disabled: boolean, whether the generated by unselect option hidden input should be disabled. Defaults to false. This option is available since version 2.0.16.
  • encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if item option is set.
  • strict: boolean, if $selection is an array and this value is true a strict comparison will be performed on $items keys. Defaults to false. This option is available since 2.0.37.
  • 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

error() public static 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.

public static 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. See also tag().
  • encode: boolean, if set to false then the error message won't be encoded.
  • errorSource (since 2.0.14): \Closure|callable, callback that will be called to obtain an error message. The signature of the callback must be: function ($model, $attribute) and return a string. When not set, the $model->getFirstError() method will be called.

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

return string

The generated label tag

getId() protected static method

Returns an autogenerated ID

protected static string getId ( )
return string

Autogenerated ID

radioList() public static method

Generates a list of radio buttons.

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

public static string radioList ( $name, $selection null, $items = [], $options = [] )
$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.
  • disabled: boolean, whether the generated by unselect option hidden input should be disabled. Defaults to false. This option is available since version 2.0.16.
  • encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if item option is set.
  • strict: boolean, if $selection is an array and this value is true a strict comparison will be performed on $items keys. Defaults to false. This option is available since 2.0.37.
  • 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

staticControl() public static method

Renders Bootstrap static form control.

See also https://getbootstrap.com/docs/4.5/components/forms/#readonly-plain-text.

public static string staticControl ( $value, $options = [] )
$value string

Static control value.

$options array

The tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. There are also a special options:

return string

Generated HTML