Automatic validation failure in thinkphp

Source: Internet
Author: User

I have recently started to learn thinkphp, in the course of practice encountered some problems. Here are the questions I encountered when I was doing TP auto-verification!

Table name is Test_member

The controller code is as follows:

<?phpnamespace regiter\controller;use think\controller;class indexcontroller extends  controller {    public function index () {          $this->display ();    }    public  Function register ($email = "", $password = "", $cpassword = ", $name =" ", $phone =" ", $address =" ") {          $rdata  = array (' email ' + $email, ' password ' + $password, ' name ' + = $name, ' phone ' = $phone, ' adress ' + $address);         $User  =  d ("Member");        if  (! $User->create ($rdata)) {             //  If creation fails   indicates validation does not pass   output error message              $this->ajaxreturn ($User GetError ());        }else{            //$User- >add ($rdata);             $this->success ($ User->select ());            //  verified by   Other data operations can be performed         }    }}

the model code is as follows:

<?php/** * created by phpstorm . * user: babydragon * date: 14-8-1 * time:  pm 2:48 */ namespace regiter\model;use think\model;class membermodel extends model{     protected  $tableName  =  ' member ';     protected $_validate  = array (        array (' email ', ' require ', ' captcha must! '),  //  all have time to verify         array (' Name ', ' ', ' account name already exists! ', 0, ' unique ', 1),         array (' name ', ' CheckName ', ' account error! ', 1, ' function ', 4),  //  only validates         array (' password ') at login time , ' checkpwd ', ' Password wrong! ', 1, ' function ', 4), //  only verify      at login time;}? 

Results automatic verification is not successful! Finally found the model filename is wrong! The file name of the TP model layer should be the name of the table (the hump method is named, and the first letter capitalized ) +.class.php. And I wrote the table name +.php.

Through this lesson I summarized the use of automatic validation in TP Note: The D method is the name of the model rather than the name of the table!


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.