From 40785632ac8aacce039533bea1c01d6b72a5d784 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 17 Feb 2016 16:45:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=AA=8C=E8=AF=81=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E8=BF=94=E5=9B=9E=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=B0=83=E6=95=B4=20=E7=94=B1=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=86=B3=E5=AE=9A=E8=BF=94=E5=9B=9E=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E8=BF=98=E6=98=AF=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 7f454202..d911d2fd 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1044,7 +1044,7 @@ class Model // 匿名函数验证 支持传入当前字段和所有字段两个数据 $result = call_user_func_array($val, [$value, &$data]); } elseif (is_string($val)) { - // 行为验证 + // 行为验证 用于一次性批量验证 $result = Hook::exec($val, '', $data); } else { // 验证字段规则 @@ -1052,14 +1052,11 @@ class Model } if (true !== $result) { // 没有返回true 则表示验证失败 - if (is_array($result)) { - // 返回组装的错误信息 - $this->error = $result; + if (!empty($options['patch'])) { + // 批量验证 + $this->error[] = $result; } else { - $this->error[] = ['key' => $key, 'error' => $result]; - } - if (empty($options['patch'])) { - // 不是批量验证则返回 + $this->error = $result; return; } } @@ -1187,7 +1184,7 @@ class Model // 行为验证 $result = Hook::exec($rule, '', $data); break; - case 'filter': // 使用filter_var验证 + case 'filter': // 使用filter_var验证 $result = filter_var($value, is_int($rule) ? $rule : filter_id($rule), $options); break; case 'confirm': @@ -1198,8 +1195,8 @@ class Model $range = is_array($rule) ? $rule : explode(',', $rule); $result = 'in' == $type ? in_array($value, $range) : !in_array($value, $range); break; - case 'between':// 验证是否在某个范围 - case 'notbetween': // 验证是否不在某个范围 + case 'between': // 验证是否在某个范围 + case 'notbetween': // 验证是否不在某个范围 if (is_string($rule)) { $rule = explode(',', $rule); } @@ -1215,7 +1212,7 @@ class Model break; } // 验证失败返回错误信息 - return false === $result ? $msg : true; + return (is_array($result) || true === $result) ? $result : $msg; } /**