I am trying to add an error tag in the form.
<?= Html::error($model, 'image');?>
But I get an ErrorException
[b]
htmlspecialchars() expects parameter 1 to be string, array given.[/b]
On the other hand Active Label works fine on the same field
<?= Html::activeLabel($model, 'image');?>
Tracking back, on the BaseHtml.php
$error = $model->getFirstError($attribute);
The $error is an array, and the encode() function expects it to be an string
1. in C:\wamp\www\yii-branty\vendor\yiisoft\yii2\helpers\BaseHtml.php at line 95
* @see decode()
* @see http://www.php.net/manual/en/function.htmlspecialchars.php
*/
public static function encode($content, $doubleEncode = true)
{
return htmlspecialchars($content, ENT_QUOTES, Yii::$app->charset, $doubleEncode);
}
/**
* Decodes special HTML entities back to the corresponding characters.
* This is the opposite of [[encode()]].
2. in C:\wamp\www\yii-branty\vendor\yiisoft\yii2\helpers\BaseHtml.php – yii\helpers\BaseHtml::encode() at line 1038
{
$attribute = static::getAttributeName($attribute);
$error = $model->getFirstError($attribute);
$tag = isset($options['tag']) ? $options['tag'] : 'div';
unset($options['tag']);
return Html::tag($tag, Html::encode($error), $options);
}