-
Notifications
You must be signed in to change notification settings - Fork 23
Installation
Alexis Wurth edited this page Jan 5, 2020
·
1 revision
$ composer require awurth/slim-validation
To initialize the validator, create a new instance of Awurth\SlimValidation\Validator
Validator::__construct([ bool $showValidationRules = true [, array $defaultMessages = [] ]])
- If set to
true
, errors will be stored in an associative array with the validation rules names as the key
$errors = [
'username' => [
'length' => 'The username must have a length between 8 and 16',
'alnum' => 'The username must contain only letters (a-z) and digits (0-9)'
]
];
- If set to
false
, errors will be stored in an array of strings
$errors = [
'username' => [
'The username must have a length between 8 and 16',
'The username must contain only letters (a-z) and digits (0-9)'
]
];
An array of messages to overwrite the default Respect Validation messages
$defaultMessages = [
'length' => 'This field must have a length between {{minValue}} and {{maxValue}} characters',
'notBlank' => 'This field is required'
];
You can add the validator to the app container to access it easily through your application
$container['validator'] = function () {
return new Awurth\SlimValidation\Validator();
};