How can I access a CodeIgniter configuration varia

2019-06-16 05:42发布

I would like to access the $db['default']['dbprefix'] variable from /application/config/database.php (CodeIgniter configuration file) from within a model so I can write my own queries using the value from the file.

How can this be done?

2条回答
干净又极端
2楼-- · 2019-06-16 05:57

Try:

$this->load->database();
echo $this->db->dbprefix;

Normally you can use $this->config->item but I think that only allows variables set in $config

查看更多
SAY GOODBYE
3楼-- · 2019-06-16 06:00

The documentation says you should be using:

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

Doesn't make a huge amount of difference but could be an easier syntax.

查看更多
登录 后发表回答