Save Codeigniter config data in MySql database |
I am looking for a more elegant way to save Codeigniter config data in a MySql database.
This is my Way: ./application/hooks/load_config.php PHP Code: function load_config() { ./application/config/hooks.php PHP Code: $hook['post_controller_constructor'] = array( ./application/config/config.php PHP Code: $config['enable_hooks'] = TRUE; ./application/models/Siteconfig.php PHP Code: public function get_config() { The config-items are normaly stored in an config-array like this: PHP Code: $config["default"] = array('key' => 'value'); If I call get_config(), I get an array with another strukture: PHP Code: Array I am correcting this by using a foreach-loop: PHP Code: $result = $this->siteconfig->get_config(); Is there a more elegant, performant way? Thanks Tom
Why not just encode and decode it using json then save it to the database in a text field.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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
I droped the whole "hook" business and move it to the sideconfig model which is autoloaded. Now I set the whole config in the constructor of the MY_Controller. Unfortunately, the hook "post_controller_constructor" was too late and the hook "post_controller" was too early. But now I found a solution.
I serialize/unserialize the data-array and save it as text in the Database. Thanks for your help Tom |
Welcome Guest, Not a member yet? Register Sign In |