Posted By

traeregan on 12/02/09


Tagged

config codeigniter


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

Blux
AzizLight
dantreacy
jatap
grablermassive
camilinha
jumichot


CodeIgniter - Database Based Config


 / Published in: PHP
 

URL: http://codeigniter.com/forums/viewthread/103684/#674817

Credit: 'Jelmer' from CodeIgniter Forums

  1. Create preferences.php in your application/config/ directory.

  2. Add this to the controller that writes your config values to the database so that it will also write them to the preferences.php config file.

  3. Add 'preferences' to the config array of your application/config/autoload.php file.

  4. Access the values using $this->config->item(); like you would with any other config value.

  5. Celebrate with a beer.

  1. function _export_preferences() {
  2. $this->load->helper('file');
  3.  
  4. $preferences = $this->db->get('preferences');
  5. $preferences = $preferences->result();
  6.  
  7. $preferences_file = '<?php'."\n\n";
  8. foreach ($preferences as $row) {
  9. $preferences_file .= '$config[\''.addslashes($row->name).'\'] = \''.addslashes($row->value).'\';'."\n";
  10. }
  11.  
  12. write_file(APPPATH.'config/preferences.php', $preferences_file);
  13. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: chewbacca on November 27, 2011

Hi fand die Idee gut und habe das mal ein bisschen erweitert.

Posted By: chewbacca on November 27, 2011

CREATE TABLE IF NOT EXISTS ge_preferences ( id int(11) NOT NULL AUTOINCREMENT, modul varchar(100) COLLATE utf8unicodeci NOT NULL, name varchar(100) COLLATE utf8unicodeci NOT NULL, value text COLLATE utf8unicodeci NOT NULL, description text COLLATE utf8unicodeci NOT NULL, created datetime NOT NULL DEFAULT '0000-00-00 00:00:00', last_update datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8unicodeci AUTOINCREMENT=14 ;

Posted By: chewbacca on November 27, 2011

hmmm würde es ja gerne posten, nur scheint es hier nicht möglich zu sein. :)

You need to login to post a comment.