Database based Config library |
[eluser]steelaz[/eluser]
A while ago codearachnid posted his extension to CI base Config library to add config items from database table - wiki. I made some modification and been using it for most of my projects. Since CI Config library is loaded automagically, there's no need to load it explicitly. To start using it, add this line in your controller (constructor is a good place): Code: $this->config->load_db_items(); load_db_items() method will check if "settings" table exists and create it if necessary. Then it will read all key => value pairs in the table and add them to Config object. After load_db_items() was called, you can access you database values just like regular items, i.e.: Code: $website_name = $this->config->item('website_name'); To add or update database item use save_db_item() method, i.e.: Code: $this->config->save_db_item('website_name', 'My Website'); To remove database item use remove_db_item() method, i.e.: Code: $this->config->remove_db_item('website_name'); To install, create /application/libraries/MY_Config.php and copy/paste the code below. Change table name if you want to. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Messages In This Thread |
Database based Config library - by El Forum - 10-11-2009, 12:53 PM
Database based Config library - by El Forum - 11-18-2009, 01:58 AM
Database based Config library - by El Forum - 11-18-2009, 02:19 AM
Database based Config library - by El Forum - 11-18-2009, 02:22 AM
Database based Config library - by El Forum - 11-18-2009, 02:39 AM
Database based Config library - by El Forum - 11-18-2009, 02:45 AM
Database based Config library - by El Forum - 11-18-2009, 02:52 AM
Database based Config library - by El Forum - 11-18-2009, 03:28 AM
Database based Config library - by El Forum - 11-18-2009, 03:31 AM
Database based Config library - by El Forum - 11-18-2009, 03:52 AM
Database based Config library - by El Forum - 11-18-2009, 03:56 AM
|