增加 database.auto_timestamp 配置参数用于配置是否需要自动写入时间戳字段

This commit is contained in:
thinkphp
2016-05-23 11:47:33 +08:00
parent 80e87d1d79
commit 6172303c97
4 changed files with 42 additions and 21 deletions

View File

@@ -202,6 +202,10 @@ return [
'master_num' => 1, 'master_num' => 1,
// 指定从服务器序号 // 指定从服务器序号
'slave_no' => '', 'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 自动写入时间戳字段
'auto_timestamp' => false,
], ],
//分页配置 //分页配置
'paginate' => [ 'paginate' => [

View File

@@ -64,7 +64,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 更新自动完成列表 // 更新自动完成列表
protected $update = []; protected $update = [];
// 是否需要自动写入时间戳 // 是否需要自动写入时间戳
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp;
// 创建时间字段 // 创建时间字段
protected $createTime = 'create_time'; protected $createTime = 'create_time';
// 更新时间字段 // 更新时间字段
@@ -111,6 +111,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$this->name = basename(str_replace('\\', '/', $this->class)); $this->name = basename(str_replace('\\', '/', $this->class));
} }
if (is_null($this->autoWriteTimestamp)) {
$this->autoWriteTimestamp = $this->getConfig('auto_timestamp');
}
// 执行初始化操作 // 执行初始化操作
$this->initialize(); $this->initialize();
} }

View File

@@ -99,6 +99,8 @@ abstract class Connection
'fields_strict' => true, 'fields_strict' => true,
// 数据集返回类型 // 数据集返回类型
'resultset_type' => Db::RESULTSET_ARRAY, 'resultset_type' => Db::RESULTSET_ARRAY,
// 自动写入时间戳字段
'auto_timestamp' => false,
]; ];
// PDO连接参数 // PDO连接参数
@@ -212,9 +214,9 @@ abstract class Connection
* @param string $config 配置名称 * @param string $config 配置名称
* @return mixed * @return mixed
*/ */
public function getConfig($config) public function getConfig($config = '')
{ {
return $this->config[$config]; return $config ? $this->config[$config] : $this->config;
} }
/** /**

View File

@@ -124,7 +124,7 @@ class Query
{ {
if ($name || empty($this->table)) { if ($name || empty($this->table)) {
$name = $name ?: $this->name; $name = $name ?: $this->name;
$tableName = $this->connection->getConfig('prefix'); $tableName = $this->getConfig('prefix');
if ($name) { if ($name) {
$tableName .= Loader::parseName($name); $tableName .= Loader::parseName($name);
} }
@@ -245,6 +245,17 @@ class Query
return $this->connection->batchQuery($sql); return $this->connection->batchQuery($sql);
} }
/**
* 获取数据库的配置参数
* @access public
* @param string $name 参数名称
* @return boolean
*/
public function getConfig($name = '')
{
return $this->connection->getConfig($name);
}
/** /**
* 获取当前的builder实例对象 * 获取当前的builder实例对象
* @access protected * @access protected
@@ -532,7 +543,7 @@ class Query
} }
} }
} else { } else {
$prefix = $this->connection->getConfig('prefix'); $prefix = $this->getConfig('prefix');
// 传入的表名为数组 // 传入的表名为数组
if (is_array($join)) { if (is_array($join)) {
if (0 !== $key = key($join)) { if (0 !== $key = key($join)) {
@@ -1788,7 +1799,7 @@ class Query
} }
if (!isset($options['strict'])) { if (!isset($options['strict'])) {
$options['strict'] = $this->connection->getConfig('fields_strict'); $options['strict'] = $this->getConfig('fields_strict');
} }
foreach (['master', 'lock', 'fetch_class', 'fetch_sql', 'distinct'] as $name) { foreach (['master', 'lock', 'fetch_class', 'fetch_sql', 'distinct'] as $name) {