From 9ff150e81af06495e4e9c616f5d3702ee9c4100d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 4 Jul 2016 09:53:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84data?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index cbcb1994..bae30c64 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -204,7 +204,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess {} /** - * 设置数据对象值(不进行修改器处理) + * 设置数据对象值 * @access public * @param mixed $data 数据或者属性名 * @param mixed $value 值 @@ -212,12 +212,20 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public function data($data, $value = null) { - if (is_object($data)) { - $this->data = get_object_vars($data); - } elseif (is_array($data)) { - $this->data = $data; - } else { + if (is_string($data)) { $this->data[$data] = $value; + } else { + if (is_object($data)) { + $data = get_object_vars($data); + } + if (true === $value) { + // 数据对象赋值 + foreach ($data as $key => $value) { + $this->setAttr($key, $value, $data); + } + } else { + $this->data = $data; + } } return $this; } @@ -989,8 +997,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if ($name instanceof Query) { return $name; } - $model = new static(); - $params = func_get_args(); + $model = new static(); + $params = func_get_args(); $params[0] = $model->db(); if ($name instanceof \Closure) { call_user_func_array($name, $params);