Reputation: 11
Hi I am trying to defining constants from mysql database, but could not load the database in codeigniter config file.
$db =$CI->load->database();
$query = $db->get('constants');
foreach( $query->result() as $row ){ define($row->title, $row->value); }
But it is throwing me an error "Undefined variable: CI"
Upvotes: 0
Views: 3364
Reputation:
At the bottom of the config/config.php, paste the following code.
require_once( BASEPATH .'database/DB.php');
$db =& DB();
$query = $db->get('constants');
$result = $query->result();
foreach( $result as $row)
{
$config[$row->title] = $row->value;
}
On Controller Test
echo $this->config->item('something');
Upvotes: 1
Reputation: 4582
To use the CI super object in a config file, you must use:
$CI =& get_instance();
Upvotes: 0