Reference ThinkPHP2.0 Development Manual: ThinkPHP manual type check is only for database-level verification, so the system also has built-in automatic verification function for data objects to complete model business rule verification. In most cases, the data object is created by the $ _ POST data submitted by the form.
The code is as follows:
/*
* Login
*/
Public function Login (){
If ($ _ POST ['submit ']) {
$ DB = D ('login'); // custom Model processing
// If is automatically verified by ThinkPHP.
If (! $ DB-> create ()){
$ This-> redirect ('index/login', '', 3, 'error message:'. $ DB-> getError ().'
The system will return to re-login in 3 seconds ...');
} 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, 'error message: incorrect user name or password
The system will return to re-login in 3 seconds ...');
}
}
Return;
}
// Here, the address of the template file is encapsulated.
A ('public')-> ShowPage ('login ');
}
The code is as follows:
Class LoginModel extends Model {
// Set the data table
Protected $ tableName = 'admin ';
// Automatic verification settings
Protected $ _ validate = array (
Array ('username', 'require ', 'user name is required! ', 1 ),
Array ('userpwd', 'require ', 'password required! ', 1 ),
);
/* Automatically fill in the code to see if it cannot be automatically verified.
Protected $ _ auto = array (
Array ('status', '1', self: MODEL_INSERT ),
Array ('create _ time', 'time', self: MODEL_INSERT, 'Function '),
);*/
/* Reference ThinkPHP2.0 Development Manual: The ThinkPHP manual type check is only for database-level verification. Therefore, the system also has the built-in automatic verification function for data objects to complete model business rule verification, in most cases, the data object is created from the $ _ POST data submitted by the form. To use the automatic verification function of the system, you only need to define the $ _ validate attribute in the Model class.
*/
/* As mentioned here, you only need to define the $ _ validate attribute in the Model class. However, when using ThinkPHP2.1, it cannot pass verification. $ DB-> getError () no error cause is returned, and $ DB-> getError () returns "token form error" when refreshing"
*/
}
?>