Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to collect all Yii model validation errors

Tags:

helper

yii

Is there any inline method to collect all validation errors? Now I'm doing this:

$errors = '';
foreach($model->attributeNames() as $attr)
{
    $errors .= $model->hasErrors($attr) ? $model->getErrors($attr) : '';
}

I think this is redundant.

like image 688
Peter Lyashevich Avatar asked Jan 02 '26 08:01

Peter Lyashevich


1 Answers

You could simply use getErrors without param, it will returns the errors for all attribute.

You could also use Chtml::errorSummary, it will displays a summary of validation errors for one or several models.

like image 145
soju Avatar answered Jan 06 '26 10:01

soju



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!