mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-02 21:52:34 +08:00
Model类添加field方法 用于设置允许写入的字段 改进Query类的field方法
This commit is contained in:
@@ -40,6 +40,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
// 字段验证规则
|
||||
protected $validate;
|
||||
|
||||
// 字段属性
|
||||
protected $field = [];
|
||||
// 数据信息
|
||||
protected $data = [];
|
||||
// 缓存数据
|
||||
@@ -343,6 +345,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检测字段
|
||||
if (!empty($this->field)) {
|
||||
foreach ($data as $key => $val) {
|
||||
if (!in_array($key, $this->field)) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数据自动完成
|
||||
$this->autoCompleteData($this->auto);
|
||||
|
||||
@@ -400,6 +411,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置允许写入的字段
|
||||
* @access public
|
||||
* @param bool $update
|
||||
* @return $this
|
||||
*/
|
||||
public function field($field)
|
||||
{
|
||||
$this->field = $field;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为更新数据
|
||||
* @access public
|
||||
|
||||
@@ -367,6 +367,9 @@ class Query
|
||||
*/
|
||||
public function field($field, $except = false, $tableName = '', $prefix = '', $alias = '')
|
||||
{
|
||||
if (empty($field)) {
|
||||
return $this;
|
||||
}
|
||||
if (is_string($field)) {
|
||||
$field = explode(',', $field);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user