From 4c84b08944dae36b70adaf4cd8e0148c0885c481 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 23 Oct 2017 15:57:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=A2=9E=E5=8A=A0=E6=8E=92?= =?UTF-8?q?=E9=99=A4=E5=AD=97=E6=AE=B5=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 726110b5..c7d9a39c 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -57,6 +57,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $pk; // 数据表字段信息 留空则自动获取 protected $field = []; + // 数据排除字段 + protected $except = []; // 只读字段 protected $readonly = []; // 显示属性 @@ -262,7 +264,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function setParent($model) { $this->parent = $model; - return $this; } @@ -1139,7 +1140,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } else { $field = []; } - + if ($this->except) { + // 排除字段 + $field = array_diff($field, (array) $this->except); + } return $field; } @@ -2062,7 +2066,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function __call($method, $args) { $query = $this->db(true, false); - + if ($this->except) { + $query->field($this->except, true); + } if (method_exists($this, 'scope' . $method)) { // 动态调用命名范围 $method = 'scope' . $method; @@ -2078,6 +2084,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess { $model = new static(); $query = $model->db(); + if ($model->except) { + $query->field($model->except, true); + } if (method_exists($model, 'scope' . $method)) { // 动态调用命名范围