validation - Unique Validator - add error (warning) and return true -
what best way create validator checks if model value unique or not, not return false - shows message "the value exists" (i can still save model)?
validators don't return boolean values, add errors given model attribute(s).
one of ways (with minimal completions) using built-in uniquevalidator , saving without running validation.
at first call $model->validate()
fill model errors.
you can use $model->validate('fieldname')
validate needed field.
then call $model->save(false)
or $model->save('fieldname')
(for 1 field).
this prevent validation before saving , model values saved "as is".
another way saving 1 attribute without triggering events, etc. using updateattributes
after calling validate()
:
$model->updateattributes(['fieldname' => 'fieldvalue']);