From 6508185312c5304ca6820fabc807135c67713d3f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 19 Feb 2016 22:58:04 +0800 Subject: [PATCH] =?UTF-8?q?model=E7=B1=BB=E7=9A=84validate=E5=92=8Cauto?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=BB=A5=E5=BD=93=E5=89=8D=E6=A8=A1=E5=9E=8B=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=91=BD=E5=90=8D=E7=9A=84=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 30d7cfb2..82ea393c 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1093,30 +1093,30 @@ class Model /** * 获取数据自动验证或者完成的规则定义 * @access protected - * @param array $data 数据 + * @param mixed $rules 数据规则 * @param string $type 数据类型 支持 validate auto * @return array */ - protected function getDataRule($data, $type) + protected function getDataRule($rules, $type) { - if (is_string($data)) { - // 读取配置文件中的自动验证定义 + if (!is_array($rules)) { + // 读取配置文件中的数据类型定义 $config = Config::get($type); if ('validate' == $type && isset($config['__pattern__'])) { // 全局字段规则 $this->rule = $config['__pattern__']; } - if (strpos($data, '.')) { - list($name, $group) = explode('.', $data); + if (true === $rules) { + $name = strtolower($this->name); + } elseif (strpos($rules, '.')) { + list($name, $group) = explode('.', $rules); } else { - $name = $data; + $name = $rules; } $rules = $config[$name]; if (isset($config['__all__'])) { $rules = array_merge($config['__all__'], $rules); } - } else { - $rules = $data; } if (isset($rules['__option__'])) { // 参数设置 @@ -1980,11 +1980,11 @@ class Model /** * 设置字段验证 * @access public - * @param mixed $field 字段名或者验证规则 + * @param mixed $field 字段名或者验证规则 true表示自动读取 * @param array|null $rule 验证规则 * @return Model */ - public function validate($field, $rule = null) + public function validate($field = true, $rule = null) { if (is_array($field) || is_null($rule)) { $this->options['validate'] = $field; @@ -1997,11 +1997,11 @@ class Model /** * 设置字段完成 * @access public - * @param mixed $field 字段名或者自动完成规则 + * @param mixed $field 字段名或者自动完成规则 true 表示自动读取 * @param array|null $rule 完成规则 * @return Model */ - public function auto($field, $rule = null) + public function auto($field = true, $rule = null) { if (is_array($field) || is_null($rule)) { $this->options['auto'] = $field;