用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1732|回复: 4
收起左侧

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

[复制链接]
发表于 2014-6-27 17:02:05 | 显示全部楼层 |阅读模式
如题?网上搜了一会没找到答案。谢谢
发表于 2014-6-30 09:27:51 | 显示全部楼层
$this->db->dbprefix('tablename');

点评

同意: 5.0
Hex
同意: 5
正解  发表于 2014-6-30 13:17
发表于 2014-6-28 02:10:48 | 显示全部楼层
需求挺奇怪的,试了一下没有什么直接的方法。

写个自定义类就实现了:
1、在/application/libraries下建一个文件ReadConfig.php,内容为:
PHP复制代码
<?php  if ( ! 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中这样使用和访问变量:
PHP复制代码
        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;
        }
复制代码



亲测通过;
发表于 2014-7-1 10:35:33 | 显示全部楼层
最简单. load config

本版积分规则