$ruleSetFiles
$ruleSetFiles : array
Files to load with validation functions.
Validator
$config : \Config\Validation
Our configuration.
$view : \CodeIgniter\View\RendererInterface
The view renderer used to render validation messages.
__construct(\Config\Validation $config, \CodeIgniter\View\RendererInterface $view)
Validation constructor.
\Config\Validation | $config | |
\CodeIgniter\View\RendererInterface | $view |
run(array $data = null, string $group = null, string $db_group = null) : boolean
Runs the validation process, returning true/false determining whether validation was successful or not.
array | $data | The array of data to validate. |
string | $group | The pre-defined group of rules to apply. |
string | $db_group | The database group to use. |
check(mixed $value, string $rule, array<mixed,string> $errors = array()) : boolean
Check; runs the validation process, returning true or false determining whether validation was successful or not.
mixed | $value | Value to validation. |
string | $rule | Rule. |
array<mixed,string> | $errors | Errors. |
True if valid, else false.
withRequest(\CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request) : \CodeIgniter\Validation\ValidationInterface
Takes a Request object and grabs the input data to use from its array values.
\CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\IncomingRequest | $request |
setRule(string $field, string|null $label = null, string $rules, array $errors = array()) : $this
Sets an individual rule and custom error messages for a single field.
The custom error message should be just the messages that apply to this field, like so:
[ 'rule' => 'message', 'rule' => 'message' ]
string | $field | |
string|null | $label | |
string | $rules | |
array | $errors |
setRules(array $rules, array $errors = array()) : \CodeIgniter\Validation\ValidationInterface
Stores the rules that should be used to validate the items.
Rules should be an array formatted like:
[ 'field' => 'rule1|rule2' ]
The $errors array should be formatted like: [ 'field' => [ 'rule' => 'message', 'rule' => 'message ], ]
array | $rules | |
array | $errors | // An array of custom error messages |
loadRuleGroup(string|null $group = null) : array|\CodeIgniter\Validation\Exceptions\ValidationException|null
Loads custom rule groups (if set) into the current rules.
Rules can be pre-defined in Config\Validation and can be any name, but must all still be an array of the same format used with setRules(). Additionally, check for {group}_errors for an array of custom error messages.
string|null | $group |
setError(string $field, string $error) : \CodeIgniter\Validation\ValidationInterface
Sets the error for a specific field. Used by custom validation methods.
string | $field | |
string | $error |
reset() : \CodeIgniter\Validation\ValidationInterface
Resets the class to a blank slate. Should be called whenever you need to process more than one array.
processRules(string $field, string|null $label = null, string $value, array|null $rules = null, array $data) : boolean
Runs all of $rules against $field, until one fails, or all of them have been processed. If one fails, it adds the error to $this->errors and moves on to the next, so that we can collect all of the first errors.
string | $field | |
string|null | $label | |
string | $value | |
array|null | $rules | |
array | $data | // All of the fields to check. |