网站开发技术

记点笔记、 学点技术 欢迎交流建站技术。本站关注lamp技术

您尚未登录。

#1 2015-03-10 12:18:51

admin
管理员

ci框架中的 中如何加载配置文件 一个简化的示例

/*
file: config.php
<?php
$config['name'] = 'mysql';
$config['user'] = 'root';
 */
function get_config($replace = array()) {
    static $_config;

    if(isset($_config)) {
        echo 'here line:  ' . __LINE__ . "  is running \n ";
        return $_config[0];
    }

    include 'config.php';
    if(count ($replace) > 0) {
        foreach($replace as $key => $val) {
            if(isset($config[$key])) {
                $config[$key] = $val;
            }
        }
    }
    var_dump($config);
    return $_config[0] = &$config;
}

function config_item($item) {
    static $_config_item = array();

    if(!isset($_config_item[$item])) {

        $config = &get_config();

        if(!isset($config[$item])) {
            return FALSE;
        }
        $_config_item[$item] = $config[$item];
    }
    return $_config_item[$item];
}

get_config(array( 'user' => "new user"));

var_dump(config_item('user'));



ipbbs.net

离线

页脚

Powered by FluxBB