mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进 字段检查 增加serialize 自动完成类型
This commit is contained in:
@@ -254,7 +254,7 @@ class Model
|
|||||||
// 检查非数据字段
|
// 检查非数据字段
|
||||||
if (!empty($fields)) {
|
if (!empty($fields)) {
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
if (!in_array($key, $fields, true)) {
|
if (!in_array(strtolower($key), $fields, true)) {
|
||||||
if (Config::get('db_fields_strict')) {
|
if (Config::get('db_fields_strict')) {
|
||||||
throw new Exception(' fields not exists :[ ' . $key . ' ]');
|
throw new Exception(' fields not exists :[ ' . $key . ' ]');
|
||||||
}
|
}
|
||||||
@@ -1180,6 +1180,20 @@ class Model
|
|||||||
array_unshift($params, $value);
|
array_unshift($params, $value);
|
||||||
$result = call_user_func_array($rule, $params);
|
$result = call_user_func_array($rule, $params);
|
||||||
break;
|
break;
|
||||||
|
case 'serialize':
|
||||||
|
if (is_string($rule)) {
|
||||||
|
$rule = explode(',', $rule);
|
||||||
|
}
|
||||||
|
$serialize = [];
|
||||||
|
foreach ($rule as $name) {
|
||||||
|
if (isset($data[$name])) {
|
||||||
|
$serialize[$name] = $data[$name];
|
||||||
|
unset($data[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$fun = !empty($params['type']) ? $params['type'] : 'serialize';
|
||||||
|
$result = $fun($serialize);
|
||||||
|
break;
|
||||||
case 'ignore':
|
case 'ignore':
|
||||||
if ($rule === $value) {
|
if ($rule === $value) {
|
||||||
if (strpos($key, '.')) {
|
if (strpos($key, '.')) {
|
||||||
@@ -1415,7 +1429,7 @@ class Model
|
|||||||
$guid = md5($tableName);
|
$guid = md5($tableName);
|
||||||
$result = Cache::get($guid);
|
$result = Cache::get($guid);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$info = $this->db->getFields($tableName);
|
$info = array_change_key_case($this->db->getFields($tableName));
|
||||||
$fields = array_keys($info);
|
$fields = array_keys($info);
|
||||||
foreach ($info as $key => $val) {
|
foreach ($info as $key => $val) {
|
||||||
// 记录字段类型
|
// 记录字段类型
|
||||||
|
|||||||
Reference in New Issue
Block a user