改进模型类的allowField方法

This commit is contained in:
thinkphp
2017-01-20 12:37:51 +08:00
parent 35ae8decf7
commit 5981a54c40

View File

@@ -755,6 +755,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 检测字段 // 检测字段
if (!empty($this->field)) { if (!empty($this->field)) {
if (true === $this->field) {
$this->field = $this->db(false)->getTableInfo('', 'fields');
}
foreach ($this->data as $key => $val) { foreach ($this->data as $key => $val) {
if (!in_array($key, $this->field)) { if (!in_array($key, $this->field)) {
unset($this->data[$key]); unset($this->data[$key]);
@@ -938,9 +941,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/ */
public function allowField($field) public function allowField($field)
{ {
if (true === $field) {
$field = $this->db(false)->getTableInfo('', 'fields');
}
$this->field = $field; $this->field = $field;
return $this; return $this;
} }