Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

关于 ThinkPHP 中自动验证的问题

![图片上传中...]

    public function addUserBasicData($username,$password,$user_type,$email,$phone,$onlyuid = '598E0CD9'){
        if (empty($username)) {
            $username = "用户".mt_rand();
        }
        $data['username'] = $username;
        $data['onlyuid'] = $onlyuid;
        $data['password'] = $password;
        $data['user_type'] = $user_type;
        $data['email'] = $email;
        $data['phone'] = $phone;
        $data['regdate'] = NOW_TIME; 

        $rules = array(
            array('onlyuid','','身份重复',0,'unique',1),
            array('phone','require','手机号码非法','/^(13|14|15|16|17|18)d{9}$$/'), 
            array('phone','','您输入手机号码已经被注册!',0,'unique',1), 
            array('email','','您输入电子邮箱已经被注册!',0,'unique',1), 
            array('password','require','您尚未填写密码!'), 
            array('user_type','require','您尚未选择用户类型!'),
            array('repassword','password','确认密码不正确',0,'confirm'), 
            array('password','checkPwd','密码格式不正确',0,'function'),
        );
        if (!$this->table('yy_common_member')->validate($rules)->create()){
            $return_value["status"] = "failed";
            $return_value["status_code"] = 40000;
            $return_value["status_message"] = $this->getError();;
            $return_value["data"]=  "";
            return $return_value;
               
        }else{
            $uid = $this->table('yy_common_member')->add($data);
            $data2['uid'] = $uid;
            $return_value["status"] = "success";
            $return_value["status_code"] = 20105;
            $return_value["status_message"] = "";
            $return_value["data"]=  $this->table('yy_common_member_profile')->add($data2);
            return $return_value;
        }

    }

以上是代码片段
分别设置了
array('onlyuid','','身份重复',0,'unique',1), 和 array('phone','','您输入手机号码已经被注册!',0,'unique',1),
的验证规则。
但前者不生效,后者可以使用

报错
clipboard.png

正常
clipboard.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

这明显是sql语句报错,跟验证没关系,插入的onlyuid重复了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...