Created
March 20, 2012 09:58
-
-
Save ghengeveld/2133671 to your computer and use it in GitHub Desktop.
CotORM example model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('COT_CODE') or die('Wrong URL.'); | |
class Member extends CotORM | |
{ | |
protected $table_name = 'users'; | |
protected $columns = array( | |
'id' => array( | |
'type' => 'int', | |
'primary_key' => true, | |
'auto_increment' => true, | |
'locked' => true | |
), | |
'email' => array( | |
'type' => 'varchar', | |
'unique' => 'true', | |
'validators' => 'validate_email' | |
), | |
'passhash' => array( | |
'type' => 'varchar', | |
'maxlength' => 40, | |
'hidden' => true | |
), | |
'authtoken' => array( | |
'type' => 'varchar', | |
'maxlength' => 40, | |
'on_insert' => 'RANDOM()', | |
'on_update' => 'RANDOM()', | |
'hidden' => true | |
), | |
'firstname' => array( | |
'type' => 'varchar', | |
'maxlength' => 50 | |
), | |
'lastname' => array( | |
'type' => 'varchar', | |
'maxlength' => 50 | |
), | |
'created' => array( | |
'type' => 'int', | |
'on_insert' => 'NOW()', | |
'locked' => true | |
), | |
'updated' => array( | |
'type' => 'int', | |
'on_insert' => 'NOW()', | |
'on_update' => 'NOW()', | |
'locked' => true | |
) | |
); | |
protected function validate_email($email, $src = 'default') | |
{ | |
if (!preg_match('|^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$|i', $email)) | |
{ | |
cot_error('InvalidEmailAddress', $src); | |
return false; | |
} | |
return true; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment