Normal Mode:
1<?PHP2 classUsermodelextendsrelationmodel{3 4 5 /** Automatic Verification **/6 protected $_validate=Array( 7 /**array ([validation field],[validation Rule],[error prompt] (validation condition (default is field Validation), (additional rule), (validation time)) **/8 Array(' username ', ' ', ' the user name already exists! ', 1, ' unique '),9 Array(' Password ', ' 5,12 ', ' password too short, please re-enter! ', 1, ' length '),//Custom Function Validation password formatTen Array(' Repassword ', ' password ', ' two times password inconsistent, please confirm the input! ', 1, ' confirm '), One ); A - /*the ' callback ' and ' function ' in this additional rule must be clearly divided, ' callback is a user-defined function ', - ' function ' is the system's own functions the */ - /** Verification Conditions **/ - /** - * model::exists_validate or 0 exists field is verified (default) + * Model::must_validate or 1 must be verified - * Verify when model::value_validate or 2 value is not empty + */ A /** Verification Time **/ at /** - * Model::model_insert or 1 new data when validating - * Model::model_update or 2 edit data when validating - * Model::model_both or 3 verification in all cases (default) - * The verification time here should be noted, not only in these three cases, you can add additional verification time according to business needs. - */ in - /** Automatically added **/ to protected $_auto=Array ( + /**array ([Add field],[Add function],[Add condition],[Additional rules]) **/ - Array(' Addtime ', ' time ', 3, ' function '), the ); * $ /** Background Check password length **/Panax Notoginseng protected functionCheckpwd ($password){ - if(strlen($password) < 5){ the return false; +}Else{ A return true; the } + } - $ } $ -?>
Dynamic binding mode:
1<?PHP2 classUseractionextendsaction{3 4 Public functionUser () {5 $this-display ();6 }7 8 Public functionindex () {9 $user= D (' User ');Ten $validate=Array( One /**array ([validation field],[validation Rule],[error prompt] (validation condition (default is field Validation), (additional rule), (validation time)) **/ A Array(' username ', ' ', ' the user name already exists! ', 1, ' unique '), - Array(' Password ', ' 5,12 ', ' password too short, please re-enter! ', 1, ' length '),//Custom Function Validation password format - Array(' Repassword ', ' password ', ' two times password inconsistent, please confirm the input! ', 1, ' confirm '), the ); - $auto=Array( - Array(' Addtime ', ' time ', 3, ' function '), - ); + //built-in functions in model models - //$user->setproperty (' _validate ', $validate); + //$user->setproperty (' _auto ', $auto); A $user->validate ($validata)->auto ($auto); at if($user-Create ()) { - if($user-Add ()) { - $this->success (' Registered success '); -}Else{ - $this->error (' Registration failed '); - } in}Else{ - $this->error ($user-GetError ()); to } + } - } the?>
Auto-validation $_validate $_auto in model