yii\helpers\BaseHtml::error PHP Метод

error() публичный статический Метод

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.
Результат string the generated label tag
    public static function error($model, $attribute, $options = [])
    {
        $attribute = static::getAttributeName($attribute);
        $error = $model->getFirstError($attribute);
        $tag = ArrayHelper::remove($options, 'tag', 'div');
        $encode = ArrayHelper::remove($options, 'encode', true);
        return Html::tag($tag, $encode ? Html::encode($error) : $error, $options);
    }

Usage Example

Пример #1
0
">

        <?php 
echo $form->field($model, 'equipment')->checkboxList(['проектор' => 'Проектор', 'экран' => 'Экран']);
?>

    </div>

    <p class="lead">Абоненты / Переговорные комнаты</p>

    <?php 
if ($model->hasErrors('participantsId')) {
    ?>

        <?php 
    echo BaseHtml::error($model, 'participantsId', ['class' => 'alert alert-danger']);
    ?>

    <?php 
}
?>

    <div id="participants-container">

        <?php 
echo $this->render('_participants', ['model' => $model]);
?>

    </div>

    <?php