public static errorSummary ( |
||
$models | the model(s) whose validation errors are to be displayed. | |
$options | array | the tag options in terms of name-value pairs. The following options are specially handled: - header: string, the header HTML for the error summary. If not set, a default prompt string will be used. - footer: string, the footer HTML for the error summary. Defaults to empty string. - encode: boolean, if set to false then the error messages won't be encoded. Defaults to `true`. - showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise only the first error message for each attribute will be shown. Defaults to `false`. Option is available since 2.0.10. The rest of the options will be rendered as the attributes of the container tag. |
리턴 | string | the generated error summary |
public static function errorSummary($models, $options = [])
{
$header = isset($options['header']) ? $options['header'] : '<p>' . Yii::t('yii', 'Please fix the following errors:') . '</p>';
$footer = ArrayHelper::remove($options, 'footer', '');
$encode = ArrayHelper::remove($options, 'encode', true);
$showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false);
unset($options['header']);
$lines = [];
if (!is_array($models)) {
$models = [$models];
}
foreach ($models as $model) {
/* @var $model Model */
foreach ($model->getErrors() as $errors) {
foreach ($errors as $error) {
$line = $encode ? Html::encode($error) : $error;
if (array_search($line, $lines) === false) {
$lines[] = $line;
}
if (!$showAllErrors) {
break;
}
}
}
}
if (empty($lines)) {
// still render the placeholder for client-side validation use
$content = '<ul></ul>';
$options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none';
} else {
$content = '<ul><li>' . implode("</li>\n<li>", $lines) . '</li></ul>';
}
return Html::tag('div', $header . $content . $footer, $options);
}
echo $form->field($model, 'rec_status_id')->radioList(ArrayHelper::map(\app\models\RecStatus::find()->active()->all(), 'id', 'name'), ['class' => 'btn-group', 'data-toggle' => 'buttons', 'unselect' => null, 'item' => function ($index, $label, $name, $checked, $value) { return '<label class="btn btn-default' . ($checked ? ' active' : '') . '">' . Html::radio($name, $checked, ['value' => $value, 'class' => 'project-status-btn']) . $label . '</label>'; }]); ?> <?php echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(\app\models\User::find()->active()->all(), 'id', 'name'), ['prompt' => '']); ?> <?php echo $form->field($model, 'dc')->textInput(); ?> <div class="form-group"> <div class="col-lg-offset-2 col-lg-10"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Save') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> </div> <?php ActiveForm::end(); ?> </div> <?php if ($model->hasErrors()) { echo \kartik\growl\Growl::widget(['type' => \kartik\growl\Growl::TYPE_DANGER, 'title' => 'Необходимо исправить следующие ошибки:', 'icon' => 'glyphicon glyphicon-exclamation-sign', 'body' => \yii\helpers\BaseHtml::errorSummary($model, ['header' => '']), 'showSeparator' => true, 'delay' => 10, 'pluginOptions' => ['placement' => ['from' => 'top', 'align' => 'right']]]); }