Set Raxan config with values of a table

Discuss anything that's related to the Raxan framework

Set Raxan config with values of a table

Postby fc_Damir » Thu Feb 10, 2011 8:32 pm

Hello everyone,

I needed to give the possibility to end users of a site can change the values of the config files or those that automatically finds raxan.
I found the following solution, I would like to share with someone who might need it.

database table:

Code: Select all
CREATE TABLE IF NOT EXISTS `config` (
  `config_id_pk` int(11) NOT NULL auto_increment,
  `config_name` varchar(32) NOT NULL,
  `config_value` longtext NULL,
  PRIMARY KEY  (`config_id_pk`)
) ENGINE=innoDB DEFAULT CHARSET=utf8 ;


code that executes in a plugin page_config ():
Code: Select all
    protected function page_config($e, $page){
      $config = array();
      $config = $this->db->table('config');
      foreach($config as $val){
        if(isset($val["config_value"]) && !empty($val["config_value"]))
            $this->site_settings[$val["config_name"]] = $val["config_value"];
        }
       $this->site_settings["db.default"] = array(
         "dsn" => $this->site_settings["dsn"],
         "user" => $this->site_settings["user"],
         "password" => $this->site_settings["password"],
         "attribs" => $this->site_settings["attribs"]
       );
       unset($this->site_settings["dsn"]);
       unset($this->site_settings["user"]);
       unset($this->site_settings["password"]);
       unset($this->site_settings["attribs"]);
       foreach($this->site_settings as $k => $v){
            if(isset($v) && !empty($v)){
              if($v == "on") $v = true;
              if($v == "off") $v = false;
                Raxan::config($k, $v);
                }
              }
      }


That is all.

Best regards
Damir
fc_Damir
 
Posts: 33
Joined: Mon Jun 14, 2010 9:13 am

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron