关于验证唯一性的问题

浏览:3265 发布日期:2015/06/17 分类:求助交流
 protected $_validate=array(
        //array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间) 
        array('user_name','require','用户名不能为空',self::EXISTS_VALIDATE),
        array('user_name', '5,20', '用户名长度5-20位!', self::EXISTS_VALIDATE,'length'),
        array('user_name','unique','帐号已存在!',0,4), // 在新增的时候验证name字段是否唯一  假设4是注册则执行this->create($_POST,4)
        array('password','require','密码不能为空',self::EXISTS_VALIDATE),
        array('code','require','验证码不能为空',self::EXISTS_VALIDATE),
        array('password', '5,30', '密码长度不合法!', self::EXISTS_VALIDATE,'length'),
        array('password','checkPwd','密码格式不正确',0,'function'),  // 自定义函数验证密码格式
        array('repassword','checkPwd','密码格式不正确',0,'function'),  // 自定义函数验证密码格式
        array('repassword', 'password', '俩次输入密码不一致!', self::EXISTS_VALIDATE,'confirm'),
        array('code', '4', '请输入4位验证码', self::EXISTS_VALIDATE,'length'),
    );
我的user表,需要自动验证,处理注册和登陆以及其它事条,但是其中登陆的时候用户名,唯一性不需要验证 array('user_name','unique','帐号已存在!',0,4),我也设置了,但是在 登陆时候的执行creat($data)时间,老执行验证唯一性,怎么解决  //验证登陆
    public function checkLogin($username,$password,$code){
        $data=array(
            'user_name'=>$username,
            'password'=>$password,
            'code'=>$code,

        );
        if($this->create($data)){
            $map['user_name'] = $username;
            $map['password'] = sha1($password);
             $obj = $this->field('id,user_name,uniq_id')->where($map)->find();
            P($obj);
            echo $this->getLastSql();

        }else{
            exit( $this->getError());
        }
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>