只要添加usermodel.class.php就不能提交数据到数据库,而且没有任何提示,表单页面也没有任何提交成功或者失败的提示。
代码如下:(thinkphp 3.2)
接收表单的控制器的代码:
<code><?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller{
public function index(){
$this->display();
$user=D("User");//自动验证并没有实现,为什么?
if($user->create()){
if($user->add()){$this->success("注册成功,页面正在跳转...");}
else{$user->getError();}
}else{$user->getError();}
}
} </code>UserModel.class.php中的代码 :
<code><?php
namespace Home\Model;
use Think\Model;
class UserModel extends Model{
protected $_map=array(
"pwd2"=>"psd",//数据库中用的是psd字段
);
protected $_validate = array(
//array(验证字段1,验证规则,错误提示,[验证条件,附加规则,验证时间]),
array("uname","require","用户名不能为空",1),
array("uname","/^\w{3,16}$/","用户名必须由3-16位的数字字母下划线组成",1,"regex"),
array("uname","","用户名已经存在",1,"unique"),
array("pwd1","require","密码不能为空"),
array('pwd1', '/^\w{6,20}$/s',"密码格式不正确",1,"regex"),
array('pwd2', 'password', '两次密码不一致', 1, 'confirm'),
array("email","email","邮箱格式不正确性",1),
array("email","","邮箱已注册,请换一个邮箱","unique")
);
//自动完成
protected $_auto = array(
array('pwd2', 'md5', 3, 'function')
);
}</code>只要添加usermodel.class.php就不能提交数据到数据库,而且没有任何提示,表单页面也没有任何提交成功或者失败的提示。
代码如下:(thinkphp 3.2)
接收表单的控制器的代码:
<code><?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller{
public function index(){
$this->display();
$user=D("User");//自动验证并没有实现,为什么?
if($user->create()){
if($user->add()){$this->success("注册成功,页面正在跳转...");}
else{$user->getError();}
}else{$user->getError();}
}
} </code>UserModel.class.php中的代码 :
<code><?php
namespace Home\Model;
use Think\Model;
class UserModel extends Model{
protected $_map=array(
"pwd2"=>"psd",//数据库中用的是psd字段
);
protected $_validate = array(
//array(验证字段1,验证规则,错误提示,[验证条件,附加规则,验证时间]),
array("uname","require","用户名不能为空",1),
array("uname","/^\w{3,16}$/","用户名必须由3-16位的数字字母下划线组成",1,"regex"),
array("uname","","用户名已经存在",1,"unique"),
array("pwd1","require","密码不能为空"),
array('pwd1', '/^\w{6,20}$/s',"密码格式不正确",1,"regex"),
array('pwd2', 'password', '两次密码不一致', 1, 'confirm'),
array("email","email","邮箱格式不正确性",1),
array("email","","邮箱已注册,请换一个邮箱","unique")
);
//自动完成
protected $_auto = array(
array('pwd2', 'md5', 3, 'function')
);
}</code>
<code> $user=D("user");//自动验证并没有实现,为什么? </code>D("User") 试试 ,注意D方法实例化的时候的模型名称的大小写.
立即学习“PHP免费学习笔记(深入)”;
与数据库中的大小写要一致哦
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号