From 1c05f6d31d32e6d7209cde02a30d7b8fa3520838 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 10 Aug 2016 16:08:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84field?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=AE=9A=E4=B9=89=20varchar=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E5=B1=9E=E6=80=A7=E5=8F=AF=E4=BB=A5=E4=B8=8D?= =?UTF-8?q?=E7=94=A8=E5=AE=9A=E4=B9=89=E7=B1=BB=E5=9E=8B=EF=BC=8C=E4=BE=8B?= =?UTF-8?q?=E5=A6=82=EF=BC=9A=20protected=20$field=20=3D=20[=20=20=20=20'i?= =?UTF-8?q?d'=3D>'int','name','email','create=5Ftime'=3D>'int',=20];?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index ce5c9017..3b95aad7 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -154,12 +154,19 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (!empty($this->field)) { if (true === $this->field) { - $this->field = $this->db()->getTableInfo('', 'type'); - } - if (is_array($this->field) && key($this->field) !== 0) { - $query->setFieldType($this->field); - $this->field = array_keys($this->field); + $type = $this->db()->getTableInfo('', 'type'); + } else { + $type = []; + foreach ((array) $this->field as $key => $val) { + if (is_int($key)) { + $key = $val; + $val = 'varchar'; + } + $type[$key] = $val; + } } + $query->setFieldType($type); + $this->field = array_keys($type); $query->allowField($this->field); }