Hi people!
Very often it is necessary to show the user just first error in the form validation process.
I found only $model->firstErrors[$attribute] solution, but it does not work without $attribute value. I did not want to overload Model or use traits so I made the function for my base controller as follows:
public function firstErrorMessage($model){
if(!empty($model->errors)){
$errors=array_values($model->errors);
if($errors[0][0]!=''){return $errors[0][0];} else {return Yii::t('msg','Some data not correct.');}
} else {return '';}
}
So I can get first error of any model without specifying an attribute. But I am wandering if there any other solution? Thanks.