From 2ee49f5dcb8c951a92fc53ba7675b28c217a231e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 20 Dec 2016 14:41:27 +0800 Subject: [PATCH] =?UTF-8?q?unique=E9=AA=8C=E8=AF=81=E8=A7=84=E5=88=99?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A=E5=AE=8C=E6=95=B4=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=B1=BB=20=E5=B9=B6=E4=B8=94=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=BC=9A=E4=BC=98=E5=85=88=E6=A3=80=E6=B5=8B=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=B1=BB=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=20=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=88=99=E6=A3=80=E6=B5=8B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 28f7c350..ff9a32ea 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -13,6 +13,7 @@ namespace think; use think\File; use think\Lang; +use think\Loader; use think\Request; use think\Session; @@ -812,7 +813,17 @@ class Validate if (is_string($rule)) { $rule = explode(',', $rule); } - $db = Db::name($rule[0]); + if (false !== strpos($rule[0], '\\')) { + // 指定模型类 + $db = new $rule[0]; + } else { + $model = Loader::parseClass(Request::instance()->module, 'model', $rule[0]); + if (class_exists($model)) { + $db = new $model; + } else { + $db = Db::name($rule[0]); + } + } $key = isset($rule[1]) ? $rule[1] : $field; if (strpos($key, '^')) {