Model类增加只读字段支持

This commit is contained in:
thinkphp
2016-08-14 14:29:43 +08:00
parent f3e634f1b3
commit c436f079d0

View File

@@ -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;
}