From 22d63bc6e3766fe4a5078481a1f861c82d77f80b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 6 Apr 2016 11:09:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84valida?= =?UTF-8?q?te=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 28e72442..b757d6ff 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -342,17 +342,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param array $msg 提示信息 * @return Model */ - public function validate($rule = true, $msg = null) + public function validate($rule = true, $msg = []) { - if (true === $rule) { - $this->validate = $this->name; - } elseif (is_array($rule)) { + if (is_array($rule)) { $this->validate = [ 'rule' => $rule, - 'msg' => is_array($msg) ? $msg : [], + 'msg' => $msg, ]; } else { - $this->validate = $rule; + $this->validate = true === $rule ? strtolower($this->name) : $rule; } return $this; }