如何获取 database.php中的['default']['dbprefix'];
如题?网上搜了一会没找到答案。谢谢$this->db->dbprefix('tablename'); 需求挺奇怪的,试了一下没有什么直接的方法。
写个自定义类就实现了:
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;
}
亲测通过; 最简单. load config
页:
[1]