From c436f079d01606d6db0f1d3d1577ffa850b5dcc7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 14 Aug 2016 14:29:43 +0800 Subject: [PATCH] =?UTF-8?q?Model=E7=B1=BB=E5=A2=9E=E5=8A=A0=E5=8F=AA?= =?UTF-8?q?=E8=AF=BB=E5=AD=97=E6=AE=B5=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/think/Model.php b/library/think/Model.php index 8e460ee9..714b4277 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -60,6 +60,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $pk; // 数据表字段信息 留空则自动获取 protected $field = []; + // 只读字段 + protected $readonly = []; // 显示属性 protected $visible = []; // 隐藏属性 @@ -663,6 +665,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } } + if (!empty($this->readonly)) { + // 只读字段不允许更新 + foreach ($this->readonly as $key => $field) { + if (isset($data[$field])) { + unset($data[$field]); + } + } + } + if (empty($where) && !empty($this->updateWhere)) { $where = $this->updateWhere; }