dream798 发表于 2014-6-27 17:02:05

如何获取 database.php中的['default']['dbprefix'];

如题?网上搜了一会没找到答案。谢谢

longjianghu 发表于 2014-6-30 09:27:51

$this->db->dbprefix('tablename');

乒乓球鸡蛋 发表于 2014-6-28 02:10:48

需求挺奇怪的,试了一下没有什么直接的方法。

写个自定义类就实现了:
1、在/application/libraries下建一个文件ReadConfig.php,内容为:
<?phpif ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ReadConfig {

    public function read_config($fname)    {
            $file_path = APPPATH.'config/'.$fname.'.php';
            include($file_path);
            return $db;
    }
}

/* End of file Someclass.php */


2、在你的action中这样使用和访问变量:
        public function index()
        {
                $this->load->library('readconfig');
                $db_config=$this->readconfig->read_config('database');
                echo $db_config['default']['dbprefix'];
               
                //$dbconfig = $this->config->item('db');
                //echo $dbconfig;
        }


亲测通过;

IvanCI 发表于 2014-7-1 10:35:33

最简单. load config
页: [1]
查看完整版本: 如何获取 database.php中的['default']['dbprefix'];