Welcome Guest, Not a member yet? Register   Sign In
Conf v1.0 - Database Configuration done right
#1

[eluser]tdktank59[/eluser]
Conf


History:
After doing some research it is impossible to just extend the CI_Config class and not have some redundant code. And more of a hack then a proper solution.

So after some thinking and planning I came to a solution.
Step 1. Modify the auto loader to allow you to set a object name for any library loaded.
Note: $this->load->library() supports it so why shouldn't the autoloader?

Step 2. Modify the CI_Config class to allow the user of database or file configurations.

Step 3. Setup the autoloader to load the conf.php and assign it to $this->config instead of $this->conf basically overwriting the CI_Config.

So heres the result!

Everything should just be drop in and should not destroy any existing functionality since I setup the db loading to fail to file loading and just log a message saying it did so.

How to Use:
Autoload:
Load like normal, or with a new name
Code:
$autoload['library'] = array('database','conf'=> array('name'=>'config'));

Database Structure:
You can have as many database tables as you want, by default there is a prefix of "config_" on any table you use. However you can change this. (see below)
Just change table to what ever you would normally create a file for.
Code:
CREATE TABLE IF NOT EXISTS `config_table` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `key` varchar(255) NOT NULL,
  `value` varchar(255) NOT NULL,
  `created_on` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `key` (`key`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
To use config.php in the database make the table config_config (if you were using the prefix)

Turning on/off DB Config:
Code:
$this->use_db(TRUE/FALSE);
It is also setup so you can method chain this as well for example
Code:
$this->use_db(TRUE)->load('config');

Setting Prefix/Suffix:
Code:
$this->set_prefix($prefix);
Code:
$this->set_suffix($suffix);
These like use_db can also be method chained.

Otherwise the rest of the functionality is the same!

Download
Database Config V1.0

User Guide
Database Config User Guide

Let me know if you have any problems and I will fix them asap
Also let me know if you would like additional features. I set it up to behave like the traditional config class.
A few things some might like are the ability to save the file to the database. (good for development since you can set the file how you want it and import it straight to the database)
updating and saving values on the fly.
#2

[eluser]tdktank59[/eluser]
Updated links




Theme © iAndrew 2016 - Forum software by © MyBB