How can I access a CodeIgniter configuration variable from a model/controller?

早过忘川 提交于 2019-12-23 07:39:05

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/2271847/how-can-i-access-a-codeigniter-configuration-variable-from-a-model-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!