Class Details

Class that holds Validations errors.


Class Variables

public static mixed $DEFAULT_ERROR_MESSAGES = array( 'inclusion' => "is not included in the list", 'exclusion' => "is reserved", 'invalid' => "is invalid", 'confirmation' => "doesn't match confirmation", 'accepted' => "must be accepted", 'empty' => "can't be empty", 'blank' => "can't be blank", 'too_long' => "is too long (maximum is %d characters)", 'too_short' => "is too short (minimum is %d characters)", 'wrong_length' => "is the wrong length (should be %d characters)", 'taken' => "has already been taken", 'not_a_number' => "is not a number", 'greater_than' => "must be greater than %d", 'equal_to' => "must be equal to %d", 'less_than' => "must be less than %d", 'odd' => "must be odd", 'even' => "must be even", 'unique' => "must be unique", 'less_than_or_equal_to' => "must be less than or equal to %d", 'greater_than_or_equal_to' => "must be greater than or equal to %d" )

Class Methods

public Errors __construct ( Model $model )

Constructs an Errors object.

  • Model $model - The model the error is for
public void add ( string $attribute , string $msg )

Add an error message.

  • string $attribute - Name of an attribute on the model
  • string $msg - The error message
public void add_on_blank ( string $attribute , string $msg )

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

  • string $attribute - Name of an attribute on the model
  • string $msg - The error message
public void add_on_empty ( string $attribute , string $msg )

Adds an error message only if the attribute value is empty.

  • string $attribute - Name of an attribute on the model
  • string $msg - The error message
public void clear ( )

Clears out all error messages.

public void 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.

public array full_messages ( array $options )

Returns all the error messages as an array.

  • array $options - Options for messages

 $model->errors->full_messages();

 # array(
 #  "Name can't be blank",
 #  "State is the wrong length (should be 2 chars)"
 # )

	

public ArrayIterator getIterator ( )

Returns an iterator to the error messages.

This will allow you to iterate over the Errors object using foreach.

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

	

public boolean is_empty ( )

Returns true if there are no error messages.

public boolean is_invalid ( string $attribute )

Returns true if the specified attribute had any error messages.

  • string $attribute - Name of an attribute on the model
public string on ( string $attribute )

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

  • string $attribute - Name of an attribute on the model
public int size ( )

Returns the number of error messages there are.

public string __get ( string $attribute )

Retrieve error message for an attribute.

  • string $attribute - Name of an attribute on the model