OpenCart解读(二)设置类config
上一篇 /
下一篇 2007-10-04 13:50:51
/ 个人分类:OpenCart
文件config.php位于../library/application/config.php,调用后生成config对象,源代码中可以清楚地看到,config类有一个属性$data,四个方法set(),get(),has(),load(),其中load()方法还没有开发完成,也没有在系统中使用,作用是直接从存放参数的文件中读取参数到$data中。
<?php //config.php class Config { var $data = array();
function set($key, $value) { $this->data[$key] = $value; }
function get($key) { //ZFDemo_Log::log('library_application_config.php(Line 10)->$this->data = ' . print_r($this->data, true)); return (isset($this->data[$key]) ? $this->data[$key] : NULL); }
function has($key) { return isset($this->data[$key]); }
function load($filename) { $file = DIR_CONFIG . $filename;
if (file_exists($file)) { $cfg = array();
include($file); $this->data = array_merge($this->data, $cfg); //ZFDemo_Log::log('library_application_config.php(Line 24)->$this->data = ' . print_r($this->data, true)); } } } ?> |
在index.php中是这样对config进行调用的:
// Settings $settings = $database->getRows("select * from setting where type = 'admin' or type = 'global'"); foreach ($settings as $setting) { $config->set($setting['key'], $setting['value']); ZFDemo_Log::log('admin_index.php(line 52)->$setting=' . print_r($setting, true)); } |
为了观察config对象的$data属性中存放了什么数据,我们把一句调试语句插入到循环中(具体如何使用ZFDemo调试工具,请参见:http://www.phpchina.com/31261/viewspace_15275.html)。
打开调试信息文件log.txt,选取其中一段如下:
admin_index.php(line 52)->$setting=Array ( [setting_id] => 3937 [type] => global [group] => cod [key] => cod_sort_order [value] => 1 ) |
我们来看红色的部分,这是被存放到config对象的$data属性中的,上列的信息表示有一个系统参数“cod_sort_order”,它的值设为1
比较简单吧,config类的内容主要就是这些了,关于load()方法,我们可以期待后面新的版本中是否有需要实现。或者,可以在你自己开发的新的系统中开发利用,把存放在配置文件中的参数读入到$data属性中。
(未完待续)
导入论坛
收藏
分享给好友
管理
举报
TAG:
OpenCart
config