Skip to content
PHP Ecosystem
Explore

BaseHtml

API reference › Bootstrap 6 › BaseHtml

abstract classyii2\extensions\bootstrap6\BaseHtml
Extendsyii\helpers\Html » yii\helpers\BaseHtml
Sourcesrc/BaseHtml.php
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/.

PropertyTypeDescriptionDefined by
$attributeOrder staticarrayThe preferred order of attributes in a tag. Default: ['type', 'id', 'class', 'name', 'value', 'href', 'src', 'srcset', 'form', 'action', 'method', 'selected', 'checked', 'readonly', 'disabled', 'multiple', 'size', 'maxlength', 'width', 'height', 'rows', 'cols', 'alt', 'title', 'rel', 'media'].yii\helpers\BaseHtml
$attributeRegex staticstringRegular expression used for attribute name validation. Default: '/(^|.*\])([\w\.\+]+)(\[.*|$)/u'. Available since 2.0.12.yii\helpers\BaseHtml
$autoIdPrefix staticstringPrefix of the id values generated for checkbox and radio labels. Default: 'i'.BaseHtml
$dataAttributes staticarrayList of tag attributes that should be specially handled when their values are of array type. Default: ['aria', 'data', 'data-ng', 'ng']. Available since 2.0.3.yii\helpers\BaseHtml
$normalizeClassAttribute staticboolWhether to remove duplicated classes when rendering the class attribute. Default: true.BaseHtml
$voidElements staticarrayList of void elements (element name => 1) Default: ['area' => 1, 'base' => 1, 'br' => 1, 'col' => 1, 'command' => 1, 'embed' => 1, 'hr' => 1, 'img' => 1, 'input' => 1, 'keygen' => 1, 'link' => 1, 'meta' => 1, 'param' => 1, 'source' => 1, 'track' => 1, 'wbr' => 1].yii\helpers\BaseHtml
MethodDescriptionDefined by
a() staticGenerates a hyperlink tag.yii\helpers\BaseHtml
activeCheckbox() staticGenerates a checkbox tag together with a label for the given model attribute.yii\helpers\BaseHtml
activeCheckboxList() staticGenerates a list of checkboxes.yii\helpers\BaseHtml
activeDropDownList() staticGenerates a drop-down list for the given model attribute.yii\helpers\BaseHtml
activeFileInput() staticGenerates a file input tag for the given model attribute.yii\helpers\BaseHtml
activeHiddenInput() staticGenerates a hidden input tag for the given model attribute.yii\helpers\BaseHtml
activeHint() staticGenerates a hint tag for the given model attribute.yii\helpers\BaseHtml
activeInput() staticGenerates an input tag for the given model attribute.yii\helpers\BaseHtml
activeLabel() staticGenerates a label tag for the given model attribute.yii\helpers\BaseHtml
activeListBox() staticGenerates a list box.yii\helpers\BaseHtml
activePasswordInput() staticGenerates a password input tag for the given model attribute.yii\helpers\BaseHtml
activeRadio() staticGenerates a radio button tag together with a label for the given model attribute.yii\helpers\BaseHtml
activeRadioList() staticGenerates a list of radio buttons.yii\helpers\BaseHtml
activeStaticControl() staticGenerates a static form control for the given model attribute.BaseHtml
activeTextarea() staticGenerates a textarea tag for the given model attribute.yii\helpers\BaseHtml
activeTextInput() staticGenerates a text input tag for the given model attribute.yii\helpers\BaseHtml
addCssClass() staticAdds CSS classes to the options; enum cases are converted to their value (backed) or name (pure).BaseHtml
addCssStyle() staticAdds the specified CSS style to the HTML options.yii\helpers\BaseHtml
badge() staticGenerates a badge.BaseHtml
beginForm() staticGenerates a form start tag.yii\helpers\BaseHtml
beginTag() staticGenerates a start tag.yii\helpers\BaseHtml
button() staticGenerates a button tag.yii\helpers\BaseHtml
buttonInput() staticGenerates an input button.yii\helpers\BaseHtml
checkbox() staticGenerates a checkbox input.yii\helpers\BaseHtml
checkboxList() staticGenerates a list of Bootstrap checkboxes, each wrapped in a .form-field element.BaseHtml
closeButton() staticGenerates a close button with a translated aria-label.BaseHtml
csrfMetaTags() staticGenerates the meta tags containing CSRF token information.yii\helpers\BaseHtml
cssFile() staticGenerates a link tag that refers to an external CSS file.yii\helpers\BaseHtml
cssStyleFromArray() staticConverts a CSS style array into a string representation.yii\helpers\BaseHtml
cssStyleToArray() staticConverts a CSS style string into an array representation.yii\helpers\BaseHtml
decode() staticDecodes special HTML entities back to the corresponding characters.yii\helpers\BaseHtml
dropDownList() staticGenerates a drop-down list.yii\helpers\BaseHtml
encode() staticEncodes special characters into HTML entities.yii\helpers\BaseHtml
endForm() staticGenerates a form end tag.yii\helpers\BaseHtml
endTag() staticGenerates an end tag.yii\helpers\BaseHtml
enumValue() staticReturns the string value of an enum-typed value, validating strings against the enum.BaseHtml
error() staticBaseHtml
errorSummary() staticGenerates a summary of the validation errors.yii\helpers\BaseHtml
escapeCssIdentifier() staticEscapes a string for use as a CSS identifier in a selector, as CSS.escape() does.BaseHtml
escapeJsRegularExpression() staticEscapes regular expression to use in JavaScript.yii\helpers\BaseHtml
fileInput() staticGenerates a file input field.yii\helpers\BaseHtml
getAttributeName() staticReturns the real attribute name from the given attribute expression.yii\helpers\BaseHtml
getAttributeValue() staticReturns the value of the specified attribute name or expression.yii\helpers\BaseHtml
getInputId() staticGenerates an appropriate input ID for the specified attribute name or expression.yii\helpers\BaseHtml
getInputIdByName() staticConverts input name to ID.yii\helpers\BaseHtml
getInputName() staticGenerates an appropriate input name for the specified attribute name or expression.yii\helpers\BaseHtml
hiddenInput() staticGenerates a hidden input field.yii\helpers\BaseHtml
img() staticGenerates an image tag.yii\helpers\BaseHtml
input() staticGenerates an input type of the given type.yii\helpers\BaseHtml
jsFile() staticGenerates a script tag that refers to an external JavaScript file.yii\helpers\BaseHtml
label() staticGenerates a label tag.yii\helpers\BaseHtml
listBox() staticGenerates a list box.yii\helpers\BaseHtml
mailto() staticGenerates a mailto hyperlink.yii\helpers\BaseHtml
ol() staticGenerates an ordered list.yii\helpers\BaseHtml
passwordInput() staticGenerates a password input field.yii\helpers\BaseHtml
radio() staticGenerates a radio button input.yii\helpers\BaseHtml
radioList() staticGenerates a list of Bootstrap radios, each wrapped in a .form-field element.BaseHtml
removeCssClass() staticRemoves a CSS class from the specified options.yii\helpers\BaseHtml
removeCssStyle() staticRemoves the specified CSS style from the HTML options.yii\helpers\BaseHtml
renderSelectOptions() staticRenders the option tags that can be used by dropDownList() and listBox().yii\helpers\BaseHtml
renderTagAttributes() staticRenders the HTML tag attributes.yii\helpers\BaseHtml
resetButton() staticGenerates a reset button tag.yii\helpers\BaseHtml
resetInput() staticGenerates a reset input button.yii\helpers\BaseHtml
script() staticGenerates a script tag.yii\helpers\BaseHtml
staticControl() staticGenerates a read-only plain-text input.BaseHtml
style() staticGenerates a style tag.yii\helpers\BaseHtml
submitButton() staticGenerates a submit button tag.yii\helpers\BaseHtml
submitInput() staticGenerates a submit input button.yii\helpers\BaseHtml
tag() staticGenerates a complete HTML tag.yii\helpers\BaseHtml
textarea() staticGenerates a text area input.yii\helpers\BaseHtml
textInput() staticGenerates a text input field.yii\helpers\BaseHtml
theme() staticAdds the theme-{value} class to the options.BaseHtml
ul() staticGenerates an unordered list.yii\helpers\BaseHtml
activeBooleanInput() protected staticGenerates a boolean input This method is mainly called by activeCheckbox() and activeRadio().yii\helpers\BaseHtml
activeListInput() protected staticGenerates a list of input fields.yii\helpers\BaseHtml
booleanInput() protected staticGenerates a Bootstrap checkbox, switch, or radio.BaseHtml
getId() protected staticReturns the next auto-generated id for checkbox and radio labels.BaseHtml
setActivePlaceholder() protected staticGenerate placeholder from model attribute label.yii\helpers\BaseHtml
public static function activeStaticControl(yii\base\Model $model, string $attribute, mixed[] $options = []): string

Generates a static form control for the given model attribute.

The value option, when present, replaces the attribute value.

Parameters

ParameterTypeDescription
$modelyii\base\ModelModel holding the attribute.
$attributestringAttribute name or expression.
$optionsmixed[]Tag attributes, see staticControl().

Returns

string: Generated HTML.

public static function addCssClass(array<yii2\extensions\bootstrap6\TKey, mixed> &$options, mixed[]|string|Stringable|UnitEnum $class): void

Adds CSS classes to the options; enum cases are converted to their value (backed) or name (pure).

Parameters

ParameterTypeDescription
$optionsarray<yii2\extensions\bootstrap6\TKey, mixed>Tag attributes to modify.
$classmixed[]|string|Stringable|UnitEnumClass, 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.
public static function badge(string|Stringable $label, string|yii2\extensions\bootstrap6\enum\Theme|null $theme = null, mixed[] $options = []): string

Generates a badge.

The encode option controls whether the label is HTML-encoded (default true).

Parameters

ParameterTypeDescription
$labelstring|StringableBadge content.
$themestring|yii2\extensions\bootstrap6\enum\Theme|nullTheme color, or null for the default color.
$optionsmixed[]Tag attributes.

Returns

string: Generated HTML, for example <span class="badge theme-primary">New</span>.

See also

public static function checkboxList(string $name, mixed[]|string|null $selection = null, mixed[] $items = [], mixed[] $options = []): string

Generates 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-5 on the container instead of form-group).
  • itemOptions['wrapperOptions']: array, HTML attributes of each .form-field item wrapper, for example form-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

ParameterTypeDescription
$namestringInput name; [] is appended when missing.
$selectionmixed[]|string|nullSelected value or values.
$itemsmixed[]Data items, value => label.
$optionsmixed[]Container attributes and the special options above.

Returns

string

See also

public static function closeButton(mixed[] $options = []): string

Generates a close button with a translated aria-label.

Parameters

ParameterTypeDescription
$optionsmixed[]Tag attributes.

Returns

string: Generated HTML, for example <button type="button" class="btn-close" aria-label="Close"></button>.

See also

public static function enumValue(class-string<yii2\extensions\bootstrap6\T> $enum, string|yii2\extensions\bootstrap6\T|null $value, string $property, bool $responsive = false): string|null

Returns 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

ParameterTypeDescription
$enumclass-string<yii2\extensions\bootstrap6\T>String-backed enum the value belongs to.
$valuestring|yii2\extensions\bootstrap6\T|nullEnum case, its string value, or null.
$propertystringProperty name reported in the exception message.
$responsiveboolWhether to accept breakpoint-prefixed values.

Returns

string|null: Value of the enum case, the validated string, or null.

Throws

public static function error(yii\base\Model $model, string $attribute, mixed[] $options = []): string

Parameters

ParameterTypeDescription
$modelyii\base\ModelModel holding the attribute.
$attributestringAttribute name or expression.
$optionsmixed[]Tag options; the class attribute defaults to invalid-feedback.

Returns

string

public static function escapeCssIdentifier(string $identifier): string

Escapes 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

ParameterTypeDescription
$identifierstringRaw 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

public static function radioList(string $name, mixed[]|string|null $selection = null, mixed[] $items = [], mixed[] $options = []): string

Generates a list of Bootstrap radios, each wrapped in a .form-field element.

Accepts the same options as checkboxList().

Parameters

ParameterTypeDescription
$namestringInput name.
$selectionmixed[]|string|nullSelected value.
$itemsmixed[]Data items, value => label.
$optionsmixed[]Container attributes and the special options of checkboxList().

Returns

string

See also

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

Generates a read-only plain-text input.

Parameters

ParameterTypeDescription
$valuestringControl value.
$optionsmixed[]Tag attributes.

Returns

string: Generated HTML, for example <input type="text" class="form-control-plaintext" value="x" readonly>.

See also

public static function theme(mixed[] &$options, string|yii2\extensions\bootstrap6\enum\Theme|null $theme): void

Adds the theme-{value} class to the options.

Parameters

ParameterTypeDescription
$optionsmixed[]Tag attributes to modify.
$themestring|yii2\extensions\bootstrap6\enum\Theme|nullTheme color, or null to leave the options unchanged.

Throws

protected static function booleanInput(string $type, string $name, bool $checked = false, mixed[] $options = []): string

Generates 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 .check class.
  • switchOptions: array, HTML attributes of the .switch wrapper, for example theme-success or switch-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

ParameterTypeDescription
$typestringInput type, either checkbox or radio.
$namestringInput name.
$checkedboolWhether the input is checked; the checked option takes precedence.
$optionsmixed[]Tag attributes and the special options above.

Returns

string

protected static function getId(): string

Returns the next auto-generated id for checkbox and radio labels.

Returns

string