I might be barking up completely the wrong tree so forgive me if this isn't at all how I should be doing things.
I've a config table in my database which is to hold config details for my website. I want to load this data into the config.php file for code igniter?
Is this something I should be doing or totally wrong?
If I put a database call at the top of the config.php file will this get called every time someone loads the site or just the first time?
Sorry if this sounds totally stupid I'm a bit confused.
Edit
I'm not meaning database details, for example want to store something like the amount of post to be shown per page. The script I'm creating is to be used on more than one server the amount of post per page for example needs to be editable. I could of cause load this into a session but I thought loading it as a constant*? in a config file would be a better idea.
You could create a new model that pulls the config options from the database and then autoload this model so that it's available globally. Then, you could access your options via
$this->model_name->function_name($db_column);
and have$db_column
be the name of the column for the option you're looking for and have your model function select and return the column data.Personally, I use a custom config file:
http://codeigniter.com/user_guide/libraries/config.html
This is something you shouldn't be doing. The database call is done every time a request is done, and you can't store the database credentials in the database itself.
Here is how I do this:
First, our model:
.
$config["useDatabaseConfig"] = true;
In your database, you need a "settings" table with "key" and "value" columns.
Thats all. With this model, you can set whenever you want to use database and whenever go on with config/*.php files.
Say, you can change
$config["useDatabaseConfig"]
variable right before you call this model method (then, autoload should be disabled.)I do attain the variable to the CI instance, just because it is easier and nice.
Read the config data like this:
$this->pref->sess_cookie_name