Skip to content

Instantly share code, notes, and snippets.

@ghengeveld
Created March 20, 2012 09:58
Show Gist options
  • Save ghengeveld/2133671 to your computer and use it in GitHub Desktop.
Save ghengeveld/2133671 to your computer and use it in GitHub Desktop.
CotORM example model
<?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