Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created March 11, 2009 07:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shadowhand/77363 to your computer and use it in GitHub Desktop.
Save shadowhand/77363 to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') or die('No direct script access.');
class User_Model extends ORM {
protected $ignored_columns = array('birthday_day', 'birthday_month', 'birthday_year');
public function validate(array & $array, $save = FALSE)
{
$array = Validation::factory($array)
->pre_filter('trim')
->add_rules('username', 'required', 'chars[a-z_.]')
->add_rules('password', 'required', 'length[5,127]')
->add_rules('birthday_day', 'required', 'digit')
->add_rules('birthday_month', 'required', 'digit')
->add_rules('birthday_year', 'required', 'digit');
->add_callbacks('birthday_year', array($this, 'check_birthday'));
return parent::validate($array, $save);
}
public function check_birthday(Validation $array, $field)
{
if (isset($array['birthday_day']) AND isset($array['birthday_month']) AND isset($array['birthday_year']))
{
// Create the birthday as a UNIX timestamp
$this->birthday = mktime(0, 0, 0, $array['birthday_month'], $array['birthday_day'], $array['birthday_year']);
}
}
} // End User
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment