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']); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -