Loading items from database for custom config file?

Hi I've created a config file for my site items like the site name site email and so on but i want to try and store them in the database and have the config file load them from there.

At the moment i have my config file my_config.php :

$config['site_name']  = 'My CMS';
$config['site_email']  = '';
$config['display_members'] = true;
$config['display_registration'] = true;

but what i want to do is pull it from the database so it comes as an array.

$config['site_name']  = $settings['site_name'];
$config['site_email']  = $settings['site_email'];
$config['display_members'] = $settings['login_link'];
$config['display_registration'] = $settings['register_link'];

Is there a way i can do this like i do in the controllers???


If you use the CI Active Record then you can return it as an array.

See the Users Guide on the Database Active Record and Query Results.

I have tried but i get this error

A PHP Error was encountered

Severity: Notice

Message: Undefined property: MX_Config::$load

Filename: config/my_config.php

Line Number: 3

Fatal error: Call to a member function database() on a non-object in /application/config/my_config.php on line 3

Heres the code I've tried


$query = $this->db->get('settings');
return $query->row_array();

$settings = $query;

// Site Prefs (Soon to be pulled fropm the database)
$config['site_name']  = $settings['site_name'];

Im pretty sure I've done it wrong!!!


You need to use the CI Super OBject to access anything in a custom library etc;

$CI = get_instance();


// or get it global
protected $CI;

// in your __construct() get the CI instance then access

Brilliant many thanks for your help that worked a charm!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.