From 7fb2a9e291a24f750eaf5cd28e9005854f604579 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 9 Apr 2016 13:05:40 +0800 Subject: [PATCH] =?UTF-8?q?Model=E7=B1=BB=E7=9A=84before=5Finsert=20before?= =?UTF-8?q?=5Fupdate=20=E4=BD=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index e5de7120..f0544d08 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -345,11 +345,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if ($this->isUpdate) { // 更新数据 + // 自动更新 + $this->autoCompleteData($this->update); + if (false === $this->trigger('before_update', $this)) { return false; } - // 自动更新 - $this->autoCompleteData($this->update); // 去除没有更新的字段 foreach ($this->data as $key => $val) { @@ -368,13 +369,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $this->trigger('after_update', $this); } else { // 新增数据 + // 自动写入 + $this->autoCompleteData($this->insert); + if (false === $this->trigger('before_insert', $this)) { return false; } - // 自动写入 - $this->autoCompleteData($this->insert); - $result = self::db()->insert($this->data); // 获取自动增长主键