PHP头条
热点:

ThinkPHP自动验证失败及解决方法


 /*

 * 登陆
 */
public function Login(){
if($_POST[submit]){
$DB = D(Login);//自定义Model处理
    //if里面就是ThinkPHP的自动验证了.
if(!$DB->create()){
$this->redirect(Index/Login, , 3, 错误信息: .$DB->getError().<br/>系统将于3秒后返回重新登陆...);
}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, 错误信息: 用户名或密码错误<br/>系统将于3秒后返回重新登陆...);
}
}
return ;
}
//这里只是将模板文件的地址封装了一下.
A(Public)->ShowPage(login);  
}
 
<?php
class LoginModel extends Model {
// 设置数据表
protected $tableName = admin; 
// 自动验证设置
protected $_validate = array(
array(username,require,用户名必须!, 1),
array(userpwd,require,密码必须!, 1),
);
/* 自动填充 如果不能自动验证,将这段代码取消注释看看.
protected $_auto = array(
array(status,1,self::MODEL_INSERT),
array(create_time,time,self::MODEL_INSERT,function),
);*/
/*引用ThinkPHP2.0开发手册:ThinkPHP手册类型检查只是针对数据库级别的验证,所以系统还内置了数据对象的自动验证功能来完成模型的业务规则验证,而大多数情况下面,数据对象是由表单提交的$_POST数据创建。需要使用系统的自动验证功能,只需要在Model类里面定义$_validate属性
*/
/*它这里说了,只需要在Model类里面定义$_validate属性,但是在使用ThinkPHP2.1的时候,的的确确不能通过验证,$DB->getError()无错误原因返回,且刷新的时候$DB->getError()返回"令牌表单错误"
*/
}
?>

www.phpzy.comtrue/phprm/22682.htmlTechArticleThinkPHP自动验证失败及解决方法 /* * 登陆 */ public function Login(){ if($_POST[submit]){ $DB = D(Login);//自定义Model处理 //if里面就是ThinkPHP的自动验证了. if(!$DB-create()){ $this-redirect(Index/Login, , 3, 错误...

相关文章

    暂无相关文章

PHP之友评论

今天推荐