Advertisement
Guest User

Untitled

a guest
May 28th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.69 KB | None | 0 0
  1. <?php
  2. # /app/model/users.php
  3.  
  4. class User extends AppModel{
  5.    
  6.     # table yang digunakan untuk model User
  7.     var $useTable = 'users';
  8.    
  9.     # user hasOne profile ( setiap row user cuma ada 1 profile )
  10.     var $hasOne = 'Profile';
  11.    
  12.     # untuk dropdown list
  13.     var $displayField = 'username';
  14.  
  15.    
  16.     # multiple validations on single field 
  17.     var $validate = array(
  18.    
  19.         # nama field dalam table
  20.         'username' => array(
  21.                
  22.  
  23.              # rule 1, name, tak lebih dari 10
  24.             'tak_lebih_10_aksara' => array(
  25.                 'rule' => array('maxLength', 10),
  26.                 'required' => true,
  27.                 'allowEmpty' => false,
  28.                 #'on' => 'create', // or: 'update'
  29.                 'message' => 'Username maximum 10 characters'
  30.             ),
  31.            
  32.      
  33.              # rule no 2 name, tak kurang 3
  34.             'tak_kurang_3_aksara' => array(
  35.                 'rule' => array('minLength', 3),
  36.                 'required' => true,
  37.                 'allowEmpty' => false,
  38.                 #'on' => 'create', // or: 'update'
  39.                 'message' => 'Username minimum 3 characters'
  40.             ),
  41.            
  42.             # rule no 3, mesti unik
  43.             'mesti_unik' => array(
  44.                 'rule' => 'isUnique',
  45.                 'message' => 'This username has already been taken.'
  46.             ),
  47.    
  48.             # rule no , mesti alphaNumeric
  49.             'huruf_nombor' => array(
  50.                 'rule' => 'alphaNumeric',
  51.                 'message' => 'This username must only contains number and string'
  52.             ),     
  53.  
  54.         ), // column 'username'
  55.        
  56.        
  57.         # nama field dalam table
  58.         'password' => array(
  59.                
  60.  
  61.              # rule 1, name, tak lebih dari 10
  62.             'tak_lebih_10_aksara' => array(
  63.                 'rule' => array('maxLength', 10),
  64.                 'required' => true,
  65.                 'allowEmpty' => false,
  66.                 #'on' => 'create', // or: 'update'
  67.                 'message' => 'Password maximum 10 characters'
  68.             ),
  69.            
  70.      
  71.              # rule no 2 name, tak kurang 3
  72.             'tak_kurang_3_aksara' => array(
  73.                 'rule' => array('minLength', 3),
  74.                 'required' => true,
  75.                 'allowEmpty' => false,
  76.                 #'on' => 'create', // or: 'update'
  77.                 'message' => 'Password minimum 3 characters'
  78.             ),
  79.            
  80.        
  81.         ), // column 'username'
  82.            
  83.        
  84.         # nama field dalam table
  85.         'email' => array(
  86.                
  87.              # rule 1, valid email
  88.             'format_email' => array(
  89.                 'rule' => array('email', true),
  90.                 'required' => true,
  91.                 'allowEmpty' => false,
  92.                 'on' => 'create', // or: 'update'
  93.                 'message' => 'Please supply valid email'
  94.             ),
  95.            
  96.         # mesti unik
  97.             'mesti_unik' => array(
  98.                 'rule' => 'isUnique',
  99.                 'message' => 'This email has already been taken.'
  100.             ),     
  101.                
  102.         ), //column ' description'
  103.    
  104.     ); // end validation
  105.    
  106.    
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement