[eluser]Twisted1919[/eluser]
Take a look here , this is what i use :
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Config extends CI_Config{
private $ci = NULL;
public function __construct()
{
parent::CI_Config();
}
public function load_db_items()
{
if (is_null($this->ci)) { $this->ci =& get_instance(); }
/*We already have the table, no use to verify this always .
if (!$this->ci->db->table_exists($this->table))
{
$this->create_table();
}
*/
$result = array();
if( ! $result = $this->ci->cache->get(md5('general_config')))
{
$query = $this->ci->db->get(TBL_CONFIG);
if($query->num_rows() > 0)
{
$result = $query->result();
$this->ci->cache->write($result,md5('general_config'));
}
}
if( count($result) > 0 )
{
foreach ($result as $row)
{
$this->set_item($row->key, $row->value);
}
}
}
public function save_db_item($key, $value)
{
if (is_null($this->ci)) { $this->ci =& get_instance(); }
$where = array('key' => $key);
$found = $this->ci->db->get_where(TBL_CONFIG, $where, 1);
$this->ci->cache->delete(md5('general_config'));
if ($found->num_rows > 0)
{
return $this->ci->db->update(TBL_CONFIG, array('value' => $value), $where);
}
else
{
return $this->ci->db->insert(TBL_CONFIG, array('key' => $key, 'value' => $value));
}
}
public function remove_db_item($key)
{
if (is_null($this->ci)) { $this->ci =& get_instance(); }
$this->ci->cache->delete(md5('general_config'));
return $this->ci->db->delete(TBL_CONFIG, array('key' => $key));
}
public function create_table()
{
if (is_null($this->ci)) { $this->ci =& get_instance(); }
$this->ci->load->dbforge();
$this->ci->dbforge->add_field("`id` int(11) NOT NULL auto_increment");
$this->ci->dbforge->add_field("`updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP");
$this->ci->dbforge->add_field("`key` varchar(255) NOT NULL");
$this->ci->dbforge->add_field("`value` text NOT NULL");
$this->ci->dbforge->add_key('id', TRUE);
$this->ci->dbforge->create_table(TBL_CONFIG, TRUE);
}
//
}
/* End of file MY_Config.php */