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!