BaseHtml
API reference › Bootstrap 6 › BaseHtml
1 subclass
Provides the Bootstrap 6 implementation of Html.
Checkboxes and radios render the .check and .radio classes, switches render the .switch wrapper, and error
blocks default to .invalid-feedback.
See also: https://getbootstrap.com/docs/6.0/forms/field/.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attributeOrder static | array | The preferred order of attributes in a tag. Default: ['type',. | yii\ |
$attributeRegex static | string | Regular expression used for attribute name validation. Default: '/(^|. Available since 2.0.12. | yii\ |
$autoIdPrefix static | string | Prefix of the id values generated for checkbox and radio labels. Default: 'i'. | BaseHtml |
$dataAttributes static | array | List of tag attributes that should be specially handled when their values are of array type. Default: ['aria',. Available since 2.0.3. | yii\ |
$normalizeClassAttribute static | bool | Whether to remove duplicated classes when rendering the class attribute. Default: true. | BaseHtml |
$voidElements static | array | List of void elements (element name => 1) Default: ['area' => 1,. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
a() static | Generates a hyperlink tag. | yii\ |
activeCheckbox() static | Generates a checkbox tag together with a label for the given model attribute. | yii\ |
activeCheckboxList() static | Generates a list of checkboxes. | yii\ |
activeDropDownList() static | Generates a drop-down list for the given model attribute. | yii\ |
activeFileInput() static | Generates a file input tag for the given model attribute. | yii\ |
activeHiddenInput() static | Generates a hidden input tag for the given model attribute. | yii\ |
activeHint() static | Generates a hint tag for the given model attribute. | yii\ |
activeInput() static | Generates an input tag for the given model attribute. | yii\ |
activeLabel() static | Generates a label tag for the given model attribute. | yii\ |
activeListBox() static | Generates a list box. | yii\ |
activePasswordInput() static | Generates a password input tag for the given model attribute. | yii\ |
activeRadio() static | Generates a radio button tag together with a label for the given model attribute. | yii\ |
activeRadioList() static | Generates a list of radio buttons. | yii\ |
activeStaticControl() static | Generates a static form control for the given model attribute. | BaseHtml |
activeTextarea() static | Generates a textarea tag for the given model attribute. | yii\ |
activeTextInput() static | Generates a text input tag for the given model attribute. | yii\ |
addCssClass() static | Adds CSS classes to the options; enum cases are converted to their value (backed) or name (pure). | BaseHtml |
addCssStyle() static | Adds the specified CSS style to the HTML options. | yii\ |
badge() static | Generates a badge. | BaseHtml |
beginForm() static | Generates a form start tag. | yii\ |
beginTag() static | Generates a start tag. | yii\ |
button() static | Generates a button tag. | yii\ |
buttonInput() static | Generates an input button. | yii\ |
checkbox() static | Generates a checkbox input. | yii\ |
checkboxList() static | Generates a list of Bootstrap checkboxes, each wrapped in a .form-field element. | BaseHtml |
closeButton() static | Generates a close button with a translated aria-label. | BaseHtml |
csrfMetaTags() static | Generates the meta tags containing CSRF token information. | yii\ |
cssFile() static | Generates a link tag that refers to an external CSS file. | yii\ |
cssStyleFromArray() static | Converts a CSS style array into a string representation. | yii\ |
cssStyleToArray() static | Converts a CSS style string into an array representation. | yii\ |
decode() static | Decodes special HTML entities back to the corresponding characters. | yii\ |
dropDownList() static | Generates a drop-down list. | yii\ |
encode() static | Encodes special characters into HTML entities. | yii\ |
endForm() static | Generates a form end tag. | yii\ |
endTag() static | Generates an end tag. | yii\ |
enumValue() static | Returns the string value of an enum-typed value, validating strings against the enum. | BaseHtml |
error() static | BaseHtml | |
errorSummary() static | Generates a summary of the validation errors. | yii\ |
escapeCssIdentifier() static | Escapes a string for use as a CSS identifier in a selector, as CSS.escape() does. | BaseHtml |
escapeJsRegularExpression() static | Escapes regular expression to use in JavaScript. | yii\ |
fileInput() static | Generates a file input field. | yii\ |
getAttributeName() static | Returns the real attribute name from the given attribute expression. | yii\ |
getAttributeValue() static | Returns the value of the specified attribute name or expression. | yii\ |
getInputId() static | Generates an appropriate input ID for the specified attribute name or expression. | yii\ |
getInputIdByName() static | Converts input name to ID. | yii\ |
getInputName() static | Generates an appropriate input name for the specified attribute name or expression. | yii\ |
hiddenInput() static | Generates a hidden input field. | yii\ |
img() static | Generates an image tag. | yii\ |
input() static | Generates an input type of the given type. | yii\ |
jsFile() static | Generates a script tag that refers to an external JavaScript file. | yii\ |
label() static | Generates a label tag. | yii\ |
listBox() static | Generates a list box. | yii\ |
mailto() static | Generates a mailto hyperlink. | yii\ |
ol() static | Generates an ordered list. | yii\ |
passwordInput() static | Generates a password input field. | yii\ |
radio() static | Generates a radio button input. | yii\ |
radioList() static | Generates a list of Bootstrap radios, each wrapped in a .form-field element. | BaseHtml |
removeCssClass() static | Removes a CSS class from the specified options. | yii\ |
removeCssStyle() static | Removes the specified CSS style from the HTML options. | yii\ |
renderSelectOptions() static | Renders the option tags that can be used by dropDownList() and listBox(). | yii\ |
renderTagAttributes() static | Renders the HTML tag attributes. | yii\ |
resetButton() static | Generates a reset button tag. | yii\ |
resetInput() static | Generates a reset input button. | yii\ |
script() static | Generates a script tag. | yii\ |
staticControl() static | Generates a read-only plain-text input. | BaseHtml |
style() static | Generates a style tag. | yii\ |
submitButton() static | Generates a submit button tag. | yii\ |
submitInput() static | Generates a submit input button. | yii\ |
tag() static | Generates a complete HTML tag. | yii\ |
textarea() static | Generates a text area input. | yii\ |
textInput() static | Generates a text input field. | yii\ |
theme() static | Adds the theme-{value} class to the options. | BaseHtml |
ul() static | Generates an unordered list. | yii\ |
activeBooleanInput() protected static | Generates a boolean input This method is mainly called by activeCheckbox() and activeRadio(). | yii\ |
activeListInput() protected static | Generates a list of input fields. | yii\ |
booleanInput() protected static | Generates a Bootstrap checkbox, switch, or radio. | BaseHtml |
getId() protected static | Returns the next auto-generated id for checkbox and radio labels. | BaseHtml |
setActivePlaceholder() protected static | Generate placeholder from model attribute label. | yii\ |
Method details
Section titled “Method details”activeStaticControl()
Section titled “activeStaticControl() ”public static function activeStaticControl(yii\base\Model $model, string $attribute, mixed[] $options = []): stringGenerates a static form control for the given model attribute.
The value option, when present, replaces the attribute value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$model | yii\ | Model holding the attribute. |
$attribute | string | Attribute name or expression. |
$options | mixed[] | Tag attributes, see staticControl(). |
Returns
string: Generated HTML.
addCssClass()
Section titled “addCssClass() ”public static function addCssClass(array<yii2\extensions\bootstrap6\TKey, mixed> &$options, mixed[]|string|Stringable|UnitEnum $class): voidAdds CSS classes to the options; enum cases are converted to their value (backed) or name (pure).
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array<yii2\ | Tag attributes to modify. |
$class | mixed[]|Stringable|UnitEnum | Class, or list of classes (keys are kept), each a string, an enum case, or a Stringable value; null entries are ignored, and the options are left unchanged when no entry remains. |
badge()
Section titled “badge() ”public static function badge(string|Stringable $label, string|yii2\extensions\bootstrap6\enum\Theme|null $theme = null, mixed[] $options = []): stringGenerates a badge.
The encode option controls whether the label is HTML-encoded (default true).
Parameters
| Parameter | Type | Description |
|---|---|---|
$label | string|Stringable | Badge content. |
$theme | string|yii2\| | Theme color, or null for the default color. |
$options | mixed[] | Tag attributes. |
Returns
string: Generated HTML, for example <span class="badge theme-primary">New</span>.
See also
checkboxList()
Section titled “checkboxList() ”public static function checkboxList(string $name, mixed[]|string|null $selection = null, mixed[] $items = [], mixed[] $options = []): stringGenerates a list of Bootstrap checkboxes, each wrapped in a .form-field element.
Besides the core options (item, itemOptions, encode, separator, tag, unselect, strict), the
following options are handled:
inline:bool, whether to lay out the items horizontally (d-flex flex-wrap gap-5on the container instead ofform-group).itemOptions['wrapperOptions']:array, HTML attributes of each.form-fielditem wrapper, for exampleform-field-card.
When item is set, the callback renders each item and neither the wrapper nor the .form-field element is
added to it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Input name; [] is appended when missing. |
$selection | mixed[]| | Selected value or values. |
$items | mixed[] | Data items, value => label. |
$options | mixed[] | Container attributes and the special options above. |
Returns
string
See also
closeButton()
Section titled “closeButton() ”public static function closeButton(mixed[] $options = []): stringGenerates a close button with a translated aria-label.
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | mixed[] | Tag attributes. |
Returns
string: Generated HTML, for example <button type="button" class="btn-close" aria-label="Close"></button>.
See also
enumValue()
Section titled “enumValue() ”public static function enumValue(class-string<yii2\extensions\bootstrap6\T> $enum, string|yii2\extensions\bootstrap6\T|null $value, string $property, bool $responsive = false): string|nullReturns the string value of an enum-typed value, validating strings against the enum.
It is the single normalization point of the enum-typed widget properties: widgets call it from init() so that
widget() and begin() fail fast, and again while rendering to obtain the value. Enum cases are converted with
\UIAwesome\Html\Helper\Enum::normalizeStringValue(); null is returned unchanged.
With $responsive, a string may also be a space-separated list of values, each optionally prefixed with a
Breakpoint value, for example bottom-start md:top-end.
Parameters
| Parameter | Type | Description |
|---|---|---|
$enum | class-string<yii2\ | String-backed enum the value belongs to. |
$value | string| | Enum case, its string value, or null. |
$property | string | Property name reported in the exception message. |
$responsive | bool | Whether to accept breakpoint-prefixed values. |
Returns
string|null: Value of the enum case, the validated string, or null.
Throws
yii\base\InvalidConfigException: if$valueis astringthat is not a value of$enum.
error()
Section titled “error() ”public static function error(yii\base\Model $model, string $attribute, mixed[] $options = []): stringParameters
| Parameter | Type | Description |
|---|---|---|
$model | yii\ | Model holding the attribute. |
$attribute | string | Attribute name or expression. |
$options | mixed[] | Tag options; the class attribute defaults to invalid-feedback. |
Returns
string
escapeCssIdentifier()
Section titled “escapeCssIdentifier() ”public static function escapeCssIdentifier(string $identifier): stringEscapes a string for use as a CSS identifier in a selector, as CSS.escape() does.
Bytes from 0x80 up are kept verbatim, so every non-ASCII character of a UTF-8 string passes through unchanged.
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | Raw identifier, such as an element id or a class name. |
Returns
string: Identifier safe to interpolate after # or ., for example account\:edit for account:edit.
See also
radioList()
Section titled “radioList() ”public static function radioList(string $name, mixed[]|string|null $selection = null, mixed[] $items = [], mixed[] $options = []): stringGenerates a list of Bootstrap radios, each wrapped in a .form-field element.
Accepts the same options as checkboxList().
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Input name. |
$selection | mixed[]| | Selected value. |
$items | mixed[] | Data items, value => label. |
$options | mixed[] | Container attributes and the special options of checkboxList(). |
Returns
string
See also
staticControl()
Section titled “staticControl() ”public static function staticControl(string $value, mixed[] $options = []): stringGenerates a read-only plain-text input.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string | Control value. |
$options | mixed[] | Tag attributes. |
Returns
string: Generated HTML, for example <input type="text" class="form-control-plaintext" value="x" readonly>.
See also
theme()
Section titled “theme() ”public static function theme(mixed[] &$options, string|yii2\extensions\bootstrap6\enum\Theme|null $theme): voidAdds the theme-{value} class to the options.
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | mixed[] | Tag attributes to modify. |
$theme | string|yii2\| | Theme color, or null to leave the options unchanged. |
Throws
yii\base\InvalidConfigException: if$themeis astringthat is not aThemevalue.
booleanInput()
Section titled “booleanInput() ”protected static function booleanInput(string $type, string $name, bool $checked = false, mixed[] $options = []): stringGenerates a Bootstrap checkbox, switch, or radio.
Besides the core options (uncheck, label, labelOptions), the following options are handled:
switch:bool, checkbox only. Renders<div class="switch"><input type="checkbox" role="switch" switch></div>instead of the.checkclass.switchOptions:array, HTML attributes of the.switchwrapper, for exampletheme-successorswitch-lg.wrapInput:bool, whether to render the control inside the<label>instead of before it.
When label is set, the control receives an auto-generated id (see $autoIdPrefix) unless one is given,
and the label is rendered as <label for="id">. The label is NOT HTML-encoded.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | string | Input type, either checkbox or radio. |
$name | string | Input name. |
$checked | bool | Whether the input is checked; the checked option takes precedence. |
$options | mixed[] | Tag attributes and the special options above. |
Returns
string
getId()
Section titled “getId() ”protected static function getId(): stringReturns the next auto-generated id for checkbox and radio labels.
Returns
string