Eon thinkphp Handout thinkphp--automatic verification [Upper][12]

Source: Internet
Author: User

Control Layer Indexcontroller

<?phpnamespace Home\controller; UseThink\controller;classIndexcontrollerextendsController { Public functionindex () {//$food = M (' food '); Two Tables union query//var_dump ($food->field (' a.food_id,b.user_id ')->table (' __food__ A, __person__ B ')->select ()); 
            $food=d (' food '); Var_dump($food->sql_one ()->sql_two ()Select ()); $this-display (); }        //The controller Create () method automatically invokes validation//If it is directly post, use the Create () method directly (pretend that the following is the post)     Public functionLogin () {$person= D (' person '); $data[' name '] = ' 11 '; $data[' password '] = ' 1 '; $data[' repassword '] = ' 2 '; if($person->create ($data)) {        Echo' All data verified successfully! ‘; } Else {         Var_dump($person-GetError ()); }    }}

Personmodel Layer

<?phpnamespace Home\model; UseThink\model;classPersonmodelextendsModel {//Batch Verification    protected $patchValidate=true; //Automatically validate content    protected $_validate=Array(        Array(' name ', ' Require ', ' username must not be empty! ', 0, ' regex ', 3),//Array (' name ', ' email ', ' email ' format is incorrect! '),//array (' name ', ' url ', ' url ' format is not legal! '),//array (' name ', ' Currency ', ' currency format is incorrect! '),//array (' name ', ' Zip ', ' postal code must be a six-bit positive integer! '),//array (' name ', ' number ', ' must be a positive integer! '),//array (' name ', ' Integer ', ' must be an integer! '),//array (' name ', ' Double ', ' must be a floating-point number! '),//array (' name ', ' 中文版 ', ' must be in plain English! '),//array (' name ', '/^\d{3,6}$/', ' must be 3-6-bit pure number ', 0, ' regex '),//array (' name ', ' Li Tinghui ', ' pass over value not equal ', 0, ' equal ') ),//array (' name ', ' Li Tinghui ', ' passed over must be unequal ', 0, ' notequal '),        Array(' Repassword ', ' password ', ' Two values not equal ', 0, ' confirm '),Array(' name ', ' checklength ', ' username must be in 3-5 bits ', 0, ' callback ', 3,Array(3,5)),    ); //Custom Validation Methods    protected functionChecklength ($str,$min,$max) {        Preg_match_all("/./",$str,$matches); $len=Count($matches[0]); if($len<$min||$len>$max) {         return false; } Else {         return true; }     }    //encapsulating SQL statements in a model definition class    protected $_scope=Array(        ' Sql_one ' =Array(            ' WHERE ' =Array(' food_id ' =Array(' GT ', 3)),        ), ' sql_two ' =Array(            ' Order ' =Array(' unit_price ' = ' DESC '), ' limit ' =>5,        ),    ); //function to create a new object PHP comes with a function     Public function__construct () {Parent::__construct (); Var_dump(' \home '); }        }

Eon thinkphp Handout thinkphp--automatic verification [Upper][12]

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.