class Errors implements IteratorAggregate (View source)

Class that holds {@link Validations} errors.

Properties

static $DEFAULT_ERROR_MESSAGES

Methods

__construct(Model $model)

Constructs an {@link Errors} object.

clear_model()

Nulls $model so we don't get pesky circular references. $model is only needed during the validation process and so can be safely cleared once that is done.

add(string $attribute, string $msg)

Add an error message.

add_on_empty(string $attribute, string $msg)

Adds an error message only if the attribute value is {@link http://www.php.net/empty empty}.

array
__get(string $attribute)

Retrieve error messages for an attribute.

add_on_blank(string $attribute, string $msg)

Adds the error message only if the attribute value was null or an empty string.

boolean
is_invalid(string $attribute)

Returns true if the specified attribute had any error messages.

string/array
on(string $attribute)

Returns the error message(s) for the specified attribute or null if none.

get_raw_errors()

Returns the internal errors object.

array
full_messages()

Returns all the error messages as an array.

array
to_array(callable $closure = null)

Returns all the error messages as an array, including error key.

string
__toString()

Convert all error messages to a String.

boolean
is_empty()

Returns true if there are no error messages.

clear()

Clears out all error messages.

int
size()

Returns the number of error messages there are.

getIterator()

Returns an iterator to the error messages.

Details

Errors __construct(Model $model)

Constructs an {@link Errors} object.

Parameters

Model $model The model the error is for

Return Value

Errors

clear_model()

Nulls $model so we don't get pesky circular references. $model is only needed during the validation process and so can be safely cleared once that is done.

add(string $attribute, string $msg)

Add an error message.

Parameters

string $attribute Name of an attribute on the model
string $msg The error message

add_on_empty(string $attribute, string $msg)

Adds an error message only if the attribute value is {@link http://www.php.net/empty empty}.

Parameters

string $attribute Name of an attribute on the model
string $msg The error message

array __get(string $attribute)

Retrieve error messages for an attribute.

Parameters

string $attribute Name of an attribute on the model

Return Value

array or null if there is no error.

add_on_blank(string $attribute, string $msg)

Adds the error message only if the attribute value was null or an empty string.

Parameters

string $attribute Name of an attribute on the model
string $msg The error message

boolean is_invalid(string $attribute)

Returns true if the specified attribute had any error messages.

Parameters

string $attribute Name of an attribute on the model

Return Value

boolean

string/array on(string $attribute)

Returns the error message(s) for the specified attribute or null if none.

Parameters

string $attribute Name of an attribute on the model

Return Value

string/array Array of strings if several error occured on this attribute.

get_raw_errors()

Returns the internal errors object.

$model->errors->get_raw_errors();

array(

"name" => array("can't be blank"),

"state" => array("is the wrong length (should be 2 chars)",

)

array full_messages()

Returns all the error messages as an array.

$model->errors->full_messages();

array(

"Name can't be blank",

"State is the wrong length (should be 2 chars)"

)

Return Value

array

array to_array(callable $closure = null)

Returns all the error messages as an array, including error key.

$model->errors->errors();

array(

"name" => array("Name can't be blank"),

"state" => array("State is the wrong length (should be 2 chars)")

)

Parameters

callable $closure Closure to fetch the errors in some other format (optional) This closure has the signature function($attribute, $message) and is called for each available error message.

Return Value

array

string __toString()

Convert all error messages to a String.

This function is called implicitely if the object is casted to a string:

echo $error;

"Name can't be blank\nState is the wrong length (should be 2 chars)"

Return Value

string

boolean is_empty()

Returns true if there are no error messages.

Return Value

boolean

clear()

Clears out all error messages.

int size()

Returns the number of error messages there are.

Return Value

int

ArrayIterator getIterator()

Returns an iterator to the error messages.

This will allow you to iterate over the {@link Errors} object using foreach.

foreach ($model->errors as $msg) echo "$msg\n";

Return Value

ArrayIterator