-
Notifications
You must be signed in to change notification settings - Fork 0
08. Validators
The default validators:
Calls the google maps API with the supplied data. This function assumes an address structure of:
$this->address = [
'Street name',
'House number',
'City',
'Zipcode'
];
Any of these can be left empty, the first result of the API call will be used to fill in the data. This function only returns false if there are no results from the API.
If the address is valid the supplied property will be changed to a string with the filled in data:
$this->address = "Street name, House number, Zipcode, City, Country";
Converts the Model property from an array of [ day, month, year ]
, to a string of d/m/Y:H:i:s
.
If the image has a size
of more than zero this function tries to save the image, and remove the previous image if it was set. If the image has a size
of zero (so no image was uploaded) the default image, as set in the config, will be used.
The supplied property will be changed to a string with the path of the image.
This validator performs an in_array()
check, to see if the supplied property is in the array supplied in the rule. For more information about how to use this rule see the Model wiki entry.
This validator must check exactly 2 properties, and checks if they are the same.
Checks if all the supplied properties have some value.
Checks if all the supplied properties are doubles.
Checks if all the supplied properties are integers.
Checks if all the supplied properties are strings.
Checks that another database row in this models table doesn't have the same value in the same column.
The validate()
function calls the validators with, the rule array and $this
as arguments.
<?php // name.php
class Name {
public static function validate( $rule, &$model ) {
// $rule = [ ['prop1', 'prop2', 'etc'], 'name' ];
foreach ( $rule[0] as $prop ) { // loops through all properties of the rule
// checks
}
return true;
}
}