Auto-validation $_validate $_auto in model

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.