ThinkPHP automatically validates the failed solution

  • 2020-05-07 19:22:03
  • OfStack

 
/* 
*  landing  
*/ 
public function Login(){ 
if($_POST['submit']){ 
$DB = D('Login');// The custom Model To deal with  
//if The inside is ThinkPHP Is automatically verified . 
if(!$DB->create()){ 
$this->redirect('Index/Login', '', 3, ' The error message : '.$DB->getError().'<br/> System will be 3 Return in seconds and login again ...'); 
}else{ 
$con['LoginName'] = $_POST['username']; 
$con['LoginPwd'] = md5($_POST['userpwd']); 
$list = $DB->where($con)->find(); 
if(count($list)>0){ 
echo 'ok'; 
}else{ 
$this->redirect('Index/Login', '', 3, ' The error message :  Wrong username or password <br/> System will be 3 Return in seconds and login again ...'); 
} 
} 
return ; 
} 
// This simply encapsulates the address of the template file 1 Under the . 
A('Public')->ShowPage('login'); 
} 

 
<?php 
class LoginModel extends Model { 
//  Setup data table  
protected $tableName = 'admin'; 
//  Automatic verification Settings  
protected $_validate = array( 
array('username','require',' Username must! ', 1), 
array('userpwd','require',' Password must! ', 1), 
); 
/*  Automatic filling   If automatic validation is not possible , Uncomment this code . 
protected $_auto = array( 
array('status','1',self::MODEL_INSERT), 
array('create_time','time',self::MODEL_INSERT,'function'), 
);*/ 
/* reference ThinkPHP2.0 Development manual :ThinkPHP Manual type checking is only for database-level validation, so the system also has built-in automatic validation for data objects, which in most cases are submitted by forms, to do business rule validation for the model $_POST Data creation. Need to use the system's automatic verification function, only need in Model Class definition $_validate attribute  
*/ 
/* It says here , Only need to Model Class definition $_validate attribute , But in use ThinkPHP2.1 when , It really doesn't pass the test ,$DB->getError() No error reason returned , And refresh $DB->getError() return " Token form error " 
*/ 
} 
?> 

Related articles: