mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
模型类增加attrCase属性 用于设置数据表的字段大小写 值和PDO的属性PDO::ATTR_CASE一致,该设置需要和数据库的params参数一起使用才有效
This commit is contained in:
@@ -32,6 +32,8 @@ class Model
|
||||
protected $name = '';
|
||||
// 数据库名称
|
||||
protected $dbName = '';
|
||||
// 数据表字段大小写
|
||||
protected $attrCase = \PDO::CASE_LOWER;
|
||||
//数据库配置
|
||||
protected $connection = [];
|
||||
// 数据表名(不包含表前缀)
|
||||
@@ -96,6 +98,10 @@ class Model
|
||||
$this->dbName = $config['db_name'];
|
||||
}
|
||||
|
||||
if (isset($config['attr_case'])) {
|
||||
$this->attrCase = $config['attr_case'];
|
||||
}
|
||||
|
||||
// 数据库初始化操作
|
||||
// 获取数据库操作对象
|
||||
// 当前模型有独立的数据库连接信息
|
||||
@@ -1242,7 +1248,7 @@ class Model
|
||||
// 行为验证
|
||||
$result = Hook::exec($rule, '', $data);
|
||||
break;
|
||||
case 'filter': // 使用filter_var验证
|
||||
case 'filter': // 使用filter_var验证
|
||||
$result = filter_var($value, is_int($rule) ? $rule : filter_id($rule), $options);
|
||||
break;
|
||||
case 'confirm':
|
||||
@@ -1253,8 +1259,8 @@ class Model
|
||||
$range = is_array($rule) ? $rule : explode(',', $rule);
|
||||
$result = 'in' == $type ? in_array($value, $range) : !in_array($value, $range);
|
||||
break;
|
||||
case 'between': // 验证是否在某个范围
|
||||
case 'notbetween': // 验证是否不在某个范围
|
||||
case 'between':// 验证是否在某个范围
|
||||
case 'notbetween': // 验证是否不在某个范围
|
||||
if (is_string($rule)) {
|
||||
$rule = explode(',', $rule);
|
||||
}
|
||||
@@ -1428,7 +1434,20 @@ class Model
|
||||
$guid = md5($tableName);
|
||||
$result = Cache::get($guid);
|
||||
if (!$result) {
|
||||
$info = array_change_key_case($this->db->getFields($tableName));
|
||||
$info = $this->db->getFields($tableName);
|
||||
// 字段大小写转换
|
||||
switch ($this->attrCase) {
|
||||
case \PDO::CASE_LOWER:
|
||||
$info = array_change_key_case($info);
|
||||
break;
|
||||
case \PDO::CASE_UPPER:
|
||||
$info = array_change_key_case($info, CASE_UPPER);
|
||||
break;
|
||||
case \PDO::CASE_NATURAL:
|
||||
default:
|
||||
// 不做转换
|
||||
}
|
||||
|
||||
$fields = array_keys($info);
|
||||
foreach ($info as $key => $val) {
|
||||
// 记录字段类型
|
||||
|
||||
@@ -58,7 +58,6 @@ class Mysql extends Driver
|
||||
$info = [];
|
||||
if ($result) {
|
||||
foreach ($result as $key => $val) {
|
||||
$val = array_change_key_case($val);
|
||||
$info[$val['field']] = [
|
||||
'name' => $val['field'],
|
||||
'type' => $val['type'],
|
||||
|
||||
@@ -111,7 +111,6 @@ class Oracle extends Driver
|
||||
$info = [];
|
||||
if ($result) {
|
||||
foreach ($result as $key => $val) {
|
||||
$val = array_change_key_case($val);
|
||||
$info[$val['column_name']] = [
|
||||
'name' => $val['column_name'],
|
||||
'type' => $val['data_type'],
|
||||
|
||||
@@ -43,7 +43,6 @@ class Sqlite extends Driver
|
||||
$info = [];
|
||||
if ($result) {
|
||||
foreach ($result as $key => $val) {
|
||||
$val = array_change_key_case($val);
|
||||
$info[$val['name']] = [
|
||||
'name' => $val['name'],
|
||||
'type' => $val['type'],
|
||||
|
||||
@@ -14,7 +14,7 @@ use think\Config;
|
||||
use think\Debug;
|
||||
|
||||
/**
|
||||
* 页面Trace调试 需要设置 'response_exit' => false 才能生效
|
||||
* 页面Trace调试
|
||||
*/
|
||||
class Trace
|
||||
{
|
||||
@@ -70,13 +70,13 @@ class Trace
|
||||
foreach ($this->tabs as $name => $title) {
|
||||
$name = strtolower($name);
|
||||
switch ($name) {
|
||||
case 'base': // 基本信息
|
||||
case 'base': // 基本信息
|
||||
$trace[$title] = $base;
|
||||
break;
|
||||
case 'file': // 文件信息
|
||||
case 'file': // 文件信息
|
||||
$trace[$title] = $info;
|
||||
break;
|
||||
default: // 调试信息
|
||||
default: // 调试信息
|
||||
if (strpos($name, '|')) {
|
||||
// 多组信息
|
||||
$names = explode('|', $name);
|
||||
|
||||
Reference in New Issue
Block a user