最近研究了一下高洛峰老师brophp 发现brophp 自动验证 type="unique" 有个问题,当更新也就是 action="mod"的时候,如果修改某字段和该记录的字段值相同的时候也会报重复,

所以对validate.class.php进行的改动:

37行:
  self::$method(self::$data[$args["NAME"]],$args["MSG"],$args["VALUE"],$args["NAME"],$args["PRI"]);

139行的 unique方法替换即可:

static function unique($value, $msg, $rules, $name, $pri) {
$pri_v=self::$data[$pri];
if(self::$db->where("$name='$value' and $pri!='$pri_v'")->total() > 0){
self::$msg[]=$msg;
self::$flag=false;
}
}

 

以后每次写对应的xml验证文件的时候 要加上pri="id"(id为标识列),如:

<input name="name" type="unique" action="both" pri="id" msg="改用户名已经注册过了"/>

相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2021-07-09
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
相关资源
相似解决方案