素材牛VIP会员
Thinkphp添加自动验证规则后无法写入数据库也没有任何报错信息,怎么回事?
 越***0  分类:ThinkPHP  人气:737  回帖:2  发布于6年前 收藏

只要添加UserModel.class.php就不能提交数据到数据库,而且没有任何提示,表单页面也没有任何提交成功或者失败的提示。
代码如下:(Thinkphp 3.2)
接收表单的控制器的代码:

<?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();}
        }    
     } 

UserModel.class.php中的代码 :

<?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')
        );

}
 标签:thinkphpphp

讨论这个帖子(2)垃圾回帖将一律封号处理……

Lv2 入门
随***@ 技术总监 6年前#1

与数据库中的大小写要一致哦

Lv6 码匠
明***e 交互设计师 6年前#2
 $user=D("user");//自动验证并没有实现,为什么? 

D("User") 试试 ,注意D方法实例化的时候的模型名称的大小写.

 文明上网,理性发言!   😉 阿里云幸运券,戳我领取