From 5b62ac29a2cdf21bd3278ae95fe269f544543b6a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 27 May 2016 18:23:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=AA=8C=E8=AF=81=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E5=9C=BA=E6=99=AF=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index e9e532cc..70745ba3 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -237,6 +237,19 @@ class Validate // 分析验证规则 $scene = $this->getScene($scene); + if (is_array($scene)) { + // 处理场景验证字段 + $change = []; + $array = []; + foreach ($scene as $k => $val) { + if (is_numeric($k)) { + $array[] = $val; + } else { + $array[] = $k; + $change[$k] = $val; + } + } + } foreach ($rules as $key => $item) { // field => rule1|rule2... field=>['rule1','rule2',...] @@ -264,8 +277,13 @@ class Validate if (!empty($scene)) { if ($scene instanceof \Closure && !call_user_func_array($scene, [$key, &$data])) { continue; - } elseif (is_array($scene) && !in_array($key, $scene)) { - continue; + } elseif (is_array($scene)) { + if (!in_array($key, $array)) { + continue; + } elseif (isset($change[$key])) { + // 重载某个验证规则 + $rule = $change[$key]; + } } }