Welcome Guest, Not a member yet? Register   Sign In
Loading items from database for custom config file?
#1

[eluser]Skoobi[/eluser]
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 :

Code:
$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.

Code:
$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???

Cheers
Chris
#2

[eluser]InsiteFX[/eluser]
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.

#3

[eluser]Skoobi[/eluser]
I have tried but i get this error


Code:
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

Code:
$this->load->database();

$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!!!


Cheers
Chris
#4

[eluser]InsiteFX[/eluser]
You need to use the CI Super OBject to access anything in a custom library etc;

Code:
$CI = get_instance();

$CI->db->get('settings');

// or get it global
protected $CI;

// in your __construct() get the CI instance then access
$this->CI->db->get('settings');
#5

[eluser]Skoobi[/eluser]
Brilliant many thanks for your help that worked a charm!

Cheers
Chris




Theme © iAndrew 2016 - Forum software by © MyBB