Welcome Guest, Not a member yet? Register   Sign In
Loading Config from Database
#5

[eluser]Arrow768[/eluser]
I solved the Problem:
hooks/Load_items.php
Code:
<?php if ( !defined('BASEPATH') ) exit('No direct script access allowed');

/*
This hook function is responsible for reading all of the settings from
the database into the config array so they can be accessed in controllers
and views with $this->config->item('whatever'); or config_item('whatever');
*/

class MY_Load extends CI_Controller{

    function Load_items()
    {

        $CI =& get_instance();  
        //var_dump($CI);

        $results = $CI->db->get('settings')->result();

        foreach ($results as $setting) {

            $CI->config->set_item($setting->id, $setting->value);

        }//End of foreach

    }
}
?>

config/hooks.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Hooks
| -------------------------------------------------------------------------
| This file lets you define "hooks" to extend CI without hacking the core
| files.  Please see the user guide for info:
|
| http://ellislab.com/codeigniter/user-guide/general/hooks.html
|
*/

$hook['pre_controller'] = array(
                                'class'    => 'MY_Load',
                                'function' => 'Load_items',
                                'filename' => 'Load_items.php',
                                'filepath' => 'hooks',
                                );

/* End of file hooks.php */
/* Location: ./application/config/hooks.php */


Messages In This Thread
Loading Config from Database - by El Forum - 09-07-2012, 11:02 AM
Loading Config from Database - by El Forum - 09-07-2012, 12:44 PM
Loading Config from Database - by El Forum - 09-07-2012, 01:11 PM
Loading Config from Database - by El Forum - 09-07-2012, 01:32 PM
Loading Config from Database - by El Forum - 09-07-2012, 01:41 PM
Loading Config from Database - by El Forum - 09-17-2012, 12:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB