public
boolean
|
#
offsetExists( mixed $attribute )
Checks if an error is defined for an attribute.
Checks if an error is defined for an attribute.
Example:
$e = new Errors();
$e['username'] = 'Funny username';
var_dump(isset($e['username']);
#=> true
var_dump(isset($e['password']);
#=> false
Returns
boolean true if an error is defined for the specified attribute, false otherwise.
Implementation of
|
public
string|array|null
|
#
offsetGet( string|null $attribute )
Returns error messages.
Example:
$e = new Errors();
var_dump($e['password']);
#=> null
$e['password'] = 'Invalid password';
var_dump($e['password']);
#=> 'Invalid password'
$e['password'] = 'Ugly password';
var_dump($e['password']);
#=> array('Invalid password', 'Ugly password')
Parameters
- $attribute
string|null $attribute The attribute that caused the error, or null if the error is global.
Returns
string|array|null Return the global error messages or the error messages attached to an attribute.
If there is only one message a string is returned, otherwise an array with all
the messages is returned. null is returned if there is no message defined.
Implementation of
|
public
|
#
offsetSet( string|null $attribute, string $message )
Adds an error message.
Example:
$e = new Errors();
$e['password'] = 'Invalid password';
$e[] = 'Requires authentication';
Parameters
- $attribute
string|null $attribute If null, the message is considered as a general error message instead
of an attribute message.
- $message
string $message The error message.
Implementation of
|
public
|
#
offsetUnset( string|null $attribute )
Removes error messages.
Parameters
- $attribute
string|null attribute If null, general message are removed, otherwise the message attached
to the attribute are removed.
Implementation of
|
public
|
#
count( )
Returns the number of errors defined.
Returns the number of errors defined.
Example:
$e = new Errors();
$e['username'] = 'Funny user name';
$e['password'] = 'Weak password';
$e['password'] = 'should have at least one digit';
count($e);
#=> 3
Implementation of
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
#
each( mixed $callback )
Iterates through errors using the specified callback.
Iterates through errors using the specified callback.
Example:
$e = new Errors();
$e['username'] = 'Funny user name';
$e['password'] = 'Weak password';
$e->each(function($attribute, $message) {
echo "$attribute => $message<br />";
});
Parameters
|
public
|
|
public
mixed
|
#
format( string $pattern, array $args = array(), array $options = array() )
Formats the given string by replacing placeholders with the values
provided.
Formats the given string by replacing placeholders with the values
provided.
Parameters
- $pattern
string $pattern The format pattern.
- $args
array $args An array of replacements for the placeholders.
- $options
array $options Options for the formatter.
Returns
mixed A string or a stringyfiable object.
See
|