Class yii\bootstrap\Html
| Inheritance | yii\bootstrap\Html » yii\bootstrap\BaseHtml » yii\helpers\Html | 
|---|---|
| Available since extension's version | 2.0.5 | 
| Source Code | https://github.com/yiisoft/yii2-bootstrap/blob/master/src/Html.php | 
Html is an enhanced version of \yii\helpers\Html helper class dedicated to the Bootstrap needs.
This class inherits all functionality available at \yii\helpers\Html and can be used as substitute.
Attention: do not confuse yii\bootstrap\Html and \yii\helpers\Html, be careful in which class you are using inside your views.
Public Methods
| Method | Description | Defined By | 
|---|---|---|
| activeStaticControl() | Generates a Bootstrap static form control for the given model attribute. | yii\bootstrap\BaseHtml | 
| checkboxList() | yii\bootstrap\BaseHtml | |
| error() | yii\bootstrap\BaseHtml | |
| icon() | Composes icon HTML for bootstrap Glyphicons. | yii\bootstrap\BaseHtml | 
| radioList() | yii\bootstrap\BaseHtml | |
| staticControl() | Renders Bootstrap static form control. | yii\bootstrap\BaseHtml | 
Method Details
Defined in: yii\bootstrap\BaseHtml::activeStaticControl()
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 | 
|---|---|---|
                public static function activeStaticControl($model, $attribute, $options = [])
{
    if (isset($options['value'])) {
        $value = $options['value'];
        unset($options['value']);
    } else {
        $value = static::getAttributeValue($model, $attribute);
    }
    return static::staticControl($value, $options);
}
            
        Defined in: yii\bootstrap\BaseHtml::checkboxList()
| public static void checkboxList ( $name, $selection = null, $items = [], $options = [] ) | ||
| $name | ||
| $selection | ||
| $items | ||
| $options | ||
                public static function checkboxList($name, $selection = null, $items = [], $options = [])
{
    if (!isset($options['item'])) {
        $itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
        $encode = ArrayHelper::getValue($options, 'encode', true);
        $options['item'] = function ($index, $label, $name, $checked, $value) use ($itemOptions, $encode) {
            $options = array_merge([
                'label' => $encode ? static::encode($label) : $label,
                'value' => $value
            ], $itemOptions);
            return '<div class="checkbox">' . Html::checkbox($name, $checked, $options) . '</div>';
        };
    }
    return parent::checkboxList($name, $selection, $items, $options);
}
            
        Defined in: yii\bootstrap\BaseHtml::error()
| public static void error ( $model, $attribute, $options = [] ) | ||
| $model | ||
| $attribute | ||
| $options | ||
                public static function error($model, $attribute, $options = [])
{
    if (!array_key_exists('tag', $options)) {
        $options['tag'] = 'p';
    }
    if (!array_key_exists('class', $options)) {
        $options['class'] = 'help-block help-block-error';
    }
    return parent::error($model, $attribute, $options);
}
            
        Defined in: yii\bootstrap\BaseHtml::icon()
Composes icon HTML for bootstrap Glyphicons.
| public static string icon ( $name, $options = [] ) | ||
| $name | string | Icon short name, for example: 'star' | 
| $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 | Icon HTML. | 
|---|---|---|
                public static function icon($name, $options = [])
{
    $tag = ArrayHelper::remove($options, 'tag', 'span');
    $classPrefix = ArrayHelper::remove($options, 'prefix', 'glyphicon glyphicon-');
    static::addCssClass($options, $classPrefix . $name);
    return static::tag($tag, '', $options);
}
            
        Defined in: yii\bootstrap\BaseHtml::radioList()
| public static void radioList ( $name, $selection = null, $items = [], $options = [] ) | ||
| $name | ||
| $selection | ||
| $items | ||
| $options | ||
                public static function radioList($name, $selection = null, $items = [], $options = [])
{
    if (!isset($options['item'])) {
        $itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
        $encode = ArrayHelper::getValue($options, 'encode', true);
        $options['item'] = function ($index, $label, $name, $checked, $value) use ($itemOptions, $encode) {
            $options = array_merge([
                'label' => $encode ? static::encode($label) : $label,
                'value' => $value
            ], $itemOptions);
            return '<div class="radio">' . static::radio($name, $checked, $options) . '</div>';
        };
    }
    return parent::radioList($name, $selection, $items, $options);
}
            
        Defined in: yii\bootstrap\BaseHtml::staticControl()
Renders Bootstrap static form control.
By default value will be HTML-encoded using encode(), you may control this behavior via 'encode' option.
See also http://getbootstrap.com/css/#forms-controls-static.
| 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 | 
|---|---|---|
                public static function staticControl($value, $options = [])
{
    static::addCssClass($options, 'form-control-static');
    $value = (string) $value;
    if (isset($options['encode'])) {
        $encode = $options['encode'];
        unset($options['encode']);
    } else {
        $encode = true;
    }
    return static::tag('p', $encode ? static::encode($value) : $value, $options);
}