Class Validation

Summary

Fully Qualified Name: CodeIgniter\Validation\Validation
Implements: ValidationInterface

Description

Validator

Methods

Name Description Defined By
__construct() Validation constructor. Validation
check() Check; runs the validation process, returning true or false determining whether validation was successful or not. Validation
getError() Returns the error(s) for a specified $field (or empty string if not set). Validation
getErrors() Returns the array of errors that were encountered during a run() call. The array should be in the following format: Validation
getRuleGroup() Get rule group. Validation
getRules() Returns all of the rules currently defined. Validation
hasError() Checks to see if an error exists for the given field. Validation
hasRule() Checks to see if the rule for key $field has been set or not. Validation
listErrors() Returns the rendered HTML of the errors as defined in $template. Validation
loadRuleGroup() Loads custom rule groups (if set) into the current rules. Validation
reset() Resets the class to a blank slate. Should be called whenever you need to process more than one array. Validation
run() Runs the validation process, returning true/false determining whether validation was successful or not. Validation
setError() Sets the error for a specific field. Used by custom validation methods. Validation
setRule() Sets an individual rule and custom error messages for a single field. Validation
setRuleGroup() Set rule group. Validation
setRules() Stores the rules that should be used to validate the items. Validation
showError() Displays a single error in formatted HTML as defined in the $template view. Validation
withRequest() Takes a Request object and grabs the input data to use from its array values. Validation

Method Details

__construct()

Validation constructor.

Parameter Name Type Description
$config \Config\Validation
$view \RendererInterface

Returns:

check()

Check; runs the validation process, returning true or false determining whether validation was successful or not.

Parameter Name Type Description
$value mixed Value
$rule string Rule.
$errors string[] Errors.

Returns: bool True if valid, else false.

getError()

Returns the error(s) for a specified $field (or empty string if not set).

Parameter Name Type Description
$field string Field.

Returns: string Error(s).

getErrors()

Returns the array of errors that were encountered during a run() call. The array should be in the following format:

[

'field1' => 'error message',
'field2' => 'error message',

]

Returns: array Excluded from code coverage because that it always run as cli

getRuleGroup()

Get rule group.

Parameter Name Type Description
$group string Group.

Returns: string[] Rule group.

getRules()

Returns all of the rules currently defined.

Returns: array

hasError()

Checks to see if an error exists for the given field.

Parameter Name Type Description
$field string

Returns: bool

hasRule()

Checks to see if the rule for key $field has been set or not.

Parameter Name Type Description
$field string

Returns: bool

listErrors()

Returns the rendered HTML of the errors as defined in $template.

Parameter Name Type Description
$template string

Returns: string

loadRuleGroup()

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.

Parameter Name Type Description
$group string|null

Returns: array|\ValidationException|null

reset()

Resets the class to a blank slate. Should be called whenever you need to process more than one array.

Returns: \CodeIgniter\Validation\ValidationInterface

run()

Runs the validation process, returning true/false determining whether validation was successful or not.

Parameter Name Type Description
$data array The
$group string The
$db_group string The

Returns: bool

setError()

Sets the error for a specific field. Used by custom validation methods.

Parameter Name Type Description
$field string
$error string

Returns: \CodeIgniter\Validation\ValidationInterface

setRule()

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'

]

Parameter Name Type Description
$field string
$label string|null
$rules string
$errors array

Returns: $this

setRuleGroup()

Set rule group.

Parameter Name Type Description
$group string Group.

Returns:

setRules()

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
   ],

]

Parameter Name Type Description
$rules array
$errors array //

Returns: \CodeIgniter\Validation\ValidationInterface

showError()

Displays a single error in formatted HTML as defined in the $template view.

Parameter Name Type Description
$field string
$template string

Returns: string

withRequest()

Takes a Request object and grabs the input data to use from its array values.

Parameter Name Type Description
$request \CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\IncomingRequest

Returns: \CodeIgniter\Validation\ValidationInterface

Top