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


Question

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
9
4/12/2011 1:30:49 PM

Accepted Answer

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

23
2/16/2010 10:13:37 AM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon