class Person extends Activerecord\Model {
static $validatesLengthOf = array(
array('name', 'within' => array(30,100),
array('state', 'is' => 2)
);
}
$person = new Person();
$person->name = 'Tito';
$person->state = 'this is not two characters';
if (!$person->is_valid())
print_r($person->errors);
Afficher le fichier
Open project: jpfuentes2/php-activerecord
Class Usage Examples
Méthode | Description | |
---|---|---|
__construct ( ActiveRecord\Model $model ) : |
Constructs a {@link Validations} object. | |
get_record ( ) | ||
rules ( ) : array | Returns validator data. | |
validate ( ) : Errors | Runs the validators. | |
validates_exclusion_of ( array $attrs ) | This is the opposite of {@link validates_include_of}. | |
validates_format_of ( array $attrs ) | Validates that a value is matches a regex. | |
validates_inclusion_of ( array $attrs ) | Validates that a value is included the specified array. | |
validates_inclusion_or_exclusion_of ( string $type, $attrs ) | Validates that a value is in or out of a specified list of values. | |
validates_length_of ( array $attrs ) | Validates the length of a value. | |
validates_numericality_of ( array $attrs ) | Validates that a value is numeric. | |
validates_presence_of ( array $attrs ) | Validates a field is not null and not blank. | |
validates_size_of ( array $attrs ) | Alias of {@link validates_length_of} | |
validates_uniqueness_of ( array $attrs ) | Validates the uniqueness of a value. |
Méthode | Description | |
---|---|---|
is_blank_with_option ( $var, &$options ) | ||
is_null_with_option ( $var, &$options ) |
public __construct ( ActiveRecord\Model $model ) : |
||
$model | ActiveRecord\Model | The model to validate |
Résultat |
public validate ( ) : Errors | ||
Résultat | Errors | the validation errors if any |
public validates_exclusion_of ( array $attrs ) | ||
$attrs | array | Validation definition |
class Person extends ActiveRecord\Model {
static $validates_format_of = array(
array('email', 'with' => '/^.*?@.*$/')
);
}
Available options:
public validates_format_of ( array $attrs ) | ||
$attrs | array | Validation definition |
class Car extends ActiveRecord\Model {
static $validates_inclusion_of = array(
array('fuel_type', 'in' => array('hyrdogen', 'petroleum', 'electric')),
);
}
Available options:
public validates_inclusion_of ( array $attrs ) | ||
$attrs | array | Validation definition |
public validates_inclusion_or_exclusion_of ( string $type, $attrs ) | ||
$type | string | Either inclusion or exclusion |
$attrs | Validation definition |
class Person extends ActiveRecord\Model {
static $validates_length_of = array(
array('name', 'within' => array(1,50))
);
}
Available options:
public validates_length_of ( array $attrs ) | ||
$attrs | array | Validation definition |
class Person extends ActiveRecord\Model {
static $validates_numericality_of = array(
array('salary', 'greater_than' => 19.99, 'less_than' => 99.99)
);
}
Available options:
public validates_numericality_of ( array $attrs ) | ||
$attrs | array | Validation definition |
class Person extends ActiveRecord\Model {
static $validates_presence_of = array(
array('first_name'),
array('last_name')
);
}
Available options:
public validates_presence_of ( array $attrs ) | ||
$attrs | array | Validation definition |
public validates_size_of ( array $attrs ) | ||
$attrs | array | Validation definition |
class Person extends ActiveRecord\Model {
static $validates_uniqueness_of = array(
array('name'),
array(array('blah','bleh'), 'message' => 'blech')
);
}
Available options:
public validates_uniqueness_of ( array $attrs ) | ||
$attrs | array | Validation definition |