ValidErrorsTrait
This extends the Validates interface with a `valid()` method that returns a boolean. The errors are stored in the model.
Tags
Table of Contents
Properties
- $_errors : array<string|int, mixed>
- This is a collection of error sets.
Methods
- clearError() : void
- Remove all errors.
- getErrors() : array<string|int, mixed>
- Get validation errors.
- getErrorSummaries() : array<string|int, string>
- Get a summary of all errors.
- getLastErrors() : array<string|int, mixed>
- Get the latest error set.
- getLastErrorSummary() : string|null
- Get the latest error message.
- hasErrors() : bool
- Has validation errors.
- valid() : bool
- Perform validation, errors are stored on the model.
- validate() : void
- Perform validation.
Properties
$_errors
This is a collection of error sets.
private
array<string|int, mixed>
$_errors
= []
[ scenario => [ item => [messages] ] ]
Methods
clearError()
Remove all errors.
public
clearError() : void
getErrors()
Get validation errors.
public
getErrors() : array<string|int, mixed>
This is a nested array of messages.
Like this:
[
'scenario1' => [
'item1' => [ 'error1', 'error2' ],
'item2' => [ 'error3', 'error4' ],
],
'scenario2' => [
'item1' => [ 'etc' ],
],
]
Return values
array<string|int, mixed> —[ scenario => [ item => [messages] ] ]
getErrorSummaries()
Get a summary of all errors.
public
getErrorSummaries() : array<string|int, string>
Return values
array<string|int, string>getLastErrors()
Get the latest error set.
public
getLastErrors() : array<string|int, mixed>
Return values
array<string|int, mixed> —[ item => [messages] ]
getLastErrorSummary()
Get the latest error message.
public
getLastErrorSummary() : string|null
Return values
string|nullhasErrors()
Has validation errors.
public
hasErrors() : bool
Return values
boolvalid()
Perform validation, errors are stored on the model.
public
valid([string|null $scenario = null ]) : bool
Parameters
- $scenario : string|null = null
Return values
bool —true if valid, false otherwise.
validate()
Perform validation.
public
abstract validate([string|null $scenario = null ]) : void
Parameters
- $scenario : string|null = null