thinkphp 控制器controller完成数据验证,validate()、create()

public function person_pic_post(){
$uid = $this->userid;
$rules = array(
//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
array('acard', 'require', '身份证正面不能为空!', 1 ),
array('bcard', 'require', '身份证反面不能为空!', 1 ),
);
$users_model=M("persion_info");
if($data = $users_model->validate($rules)->create()){
$data['utime'] = $this->ctime;
$result=$users_model->where(array('uid'=>$uid))->save($data);
}else{
$this->error($users_model->getError());
}

if($result!==false){
$this->success("认证成功!");
}else{
$this->error("认证失败!");
}
posted @ 2017-05-11 13:29  jackduan1  阅读(2105)  评论(0编辑  收藏  举报