spadefoot / kohana-orm-leap

An ORM module for the Kohana PHP framework that is designed to work with all major databases.
http://spadefoot.github.io/kohana-orm-leap/
100 stars 25 forks source link

Field validation ... just an idea #75

Open ghost opened 11 years ago

ghost commented 11 years ago

Hey,

i have the issue that the Date_Field validate method returns FALSE, because my database return value is not valid against the regular expression in the date.php validation method.

this is hard coded to if ( ! preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $value)) { return FALSE; }

i think it will be a good idea to parse the database result to a explicit format. therefore every db connection and every value of the db is in the same format after fetching.

for date i have customized the date.php and overridden the __set method like this:

public function __set($key, $value) {
    switch ($key) {
        case 'value':
            $date = date_parse($value);
            $date = mktime($date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year']);
            $value = date('Y-m-d', $date);
    }

    parent::__set($key, $value);
}

this works very well and i have the same date format on evey db.