extends abstract class Phalcon\Validation\CombinedFieldsValidator
implements Phalcon\Validation\ValidatorInterface
Check that a field is unique in the related table
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator; $validator->add('username', new UniquenessValidator([ 'model' => new Users(), 'message' => ':field must be unique' ]));
Different attribute from the field:
$validator->add('username', new UniquenessValidator([ 'model' => new Users(), 'attribute' => 'nick' ]));
In model:
$validator->add('username', new UniquenessValidator());
Combination of fields in model:
$validator->add(['firstName', 'lastName'], new UniquenessValidator());
It is possible to convert values before validation. This is useful in situations where values need to be converted to do the database lookup:
$validator->add('username', new UniquenessValidator([ 'convert' => function (array $values) { $values['username'] = strtolower($values['username']); return $values; } ]));
Executes the validation
...
The column map is used in the case to get real column name
Phalcon\Validation\Validator constructor
Checks if an option has been defined
Checks if an option is defined
Returns an option in the validator’s options Returns null if the option hasn’t set
Sets an option in the validator
© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Validation_Validator_Uniqueness.html