重新加载配置
Core_Config Core_Config::reload( [ boolean $from_db = bool true , string $type = empty ] )
参数列表
参数 类型 描述 默认值 $from_db
boolean
是否强制从数据库中读取,默认true bool true $type
string
类型 empty
Core_Config
public function reload($from_db=true, $type = '')
{
$tmpfile = $this->get_config_cache_file(Core::$project, $type);
if ($this->is_use_cache && !$from_db && is_file($tmpfile))
{
# 在data目录中直接读取
$this->config[$type] = @unserialize(file_get_contents($tmpfile));
if (!is_array($this->config[$type]))
{
$this->config[$type] = array();
}
}
else
{
# 没有缓存数据,则直接在数据库里获取
$db = new Database($this->database);
$config = $db->from($this->tablename)->where('type', $type)->get(false, true)->as_array();
if ($config)
{
$this->config = array();
foreach ($config as $item)
{
$this->config[$item['type']][$item['key_name']] = $this->data_unformat($item['value']);
}
}
else
{
$this->config = array
(
$type => array(),
);
}
if ($this->is_use_cache)
{
// 普通模式下写缓存
$rs = File::create_file($tmpfile, serialize($this->config));
if (IS_DEBUG)Core::debug()->log('save extends config cache ' . ($rs?'success':'fail').'.');
}
}
}