Welcome Guest, Not a member yet? Register   Sign In
Save Codeigniter config data in MySql database
#3

I would drop the whole "hook" business and move it all to the model which would be autoloaded.

PHP Code:
class Siteconfig_m extends CI_Model
{
 
   public function __construct()
 
   {
 
       parent::__construct();
 
       $this->get_config();
 
   }

 
   /**
     * Get the database items and add them to the super object $config item
     */
 
   public function get_config()
 
   {
 
       //using select() because it's lighter weight than get()
 
       //using result() because $config_items->item is less typing than $config_items['item'] 
 
       //and is usually easier to read. (Yes, it's a matter of opinion.)
 
       $config_items $this->db->query('select * from config')->result();  
        foreach
($config_items as $item)
 
       {
 
           //write directly to the "super object" $config array
 
           $this->config->config[$item->key] = unserialize($item->value); 
 
        }
 
   }

 
   public function set_config($key$value)
 
   {
 
       $config_data = array('key' => $key'value' => serialize($value));
 
       return $this->db->update('config'$config_data);
 
   }

Reply


Messages In This Thread
RE: Save Codeigniter config data in MySql database - by dave friend - 02-22-2018, 01:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB