From 74b0c76870fbc4bd659a03e3ace7932baa986bca Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 21 Mar 2016 14:40:06 +0800 Subject: [PATCH] =?UTF-8?q?controller=E5=92=8Cmodel=E7=B1=BB=E7=9A=84valid?= =?UTF-8?q?ate=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=20=E4=BE=8B=E5=A6=82=20$this->validate('User?= =?UTF-8?q?.edit');?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Controller.php | 15 ++++++++++++--- library/think/Model.php | 8 +++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/library/think/Controller.php b/library/think/Controller.php index 9ab859e1..cd60e4be 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -156,15 +156,24 @@ class Controller $v = Loader::validate(Config::get('default_validate')); $v->rule($validate); } else { + if (strpos($validate, '.')) { + // 支持场景 + list($validate, $scene) = explode('.', $validate); + } $v = Loader::validate($validate); + if (!empty($scene)) { + $v->scene($scene); + } } - if (is_callable($callback)) { - call_user_func_array($callback, [$v, &$data]); - } + if (is_array($message)) { $v->message($message); } + if (is_callable($callback)) { + call_user_func_array($callback, [$v, &$data]); + } + if (!$v->check($data)) { return $v->getError(); } else { diff --git a/library/think/Model.php b/library/think/Model.php index 65b03af0..72e4fe53 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -993,8 +993,14 @@ class Model $validate->rule($info['rule']); $validate->message($info['msg']); } else { - $name = is_string($info) ? $info : $this->name; + $name = is_string($info) ? $info : $this->name; + if (strpos($name, '.')) { + list($name, $scene) = explode('.', $name); + } $validate = Loader::validate($name); + if (!empty($scene)) { + $validate->scene($scene); + } } if (!$validate->check($data)) { $this->error = $validate->getError();