Welcome Guest, Not a member yet? Register   Sign In
Best place for loading web app settings from database
#1

Hi everyone! Simple question

What if I save some site settings in database, so where would be the best place for autoload it?

By now I ovveride CI_Loader function initialize

PHP Code:
public function initialize()
{
    
parent::initialize();
        
        
//Load site settings from DB
        
$CI =& get_instance();
        
$settings $CI->model_with_settings_from_database->some_method();
        foreach(
$settings As $key => $val)
        {
            
$CI->config->set_item($key$val);
        }
    } 

What u thinking about that?

Thanks!
Reply
#2

Extend the core Loader, in application/core/MY_Loader, or else make a base controller, application/core/MY_Controller.
Don't modify system/core/Loader.
Reply
#3

What kind of settings are you saving in your database?

As @ciadmin says, don't modify the system/core/Loader class because the next time you update the framework, you might ending overriding your own changes. Anyway, you could also use Hooks. Or, if it fits, create an autoloaded helper function just to load the configurations on demand.
Best regards,
José Postiga
Senior Backend Developer
Reply
#4

(This post was last modified: 01-26-2016, 09:38 AM by keulu.)

Hi scion,

I did that for a project one day.

I created a config_model, and extended the CI_Controller with my own controller (in the core folder C.F. MY_Controller)

see http://www.codeigniter.com/user_guide/ge...asses.html

PHP Code:
class MY_Controller extends CI_Controller {

        protected 
$config;
        public function 
__construct()
        {
                
parent::__construct();
                
// load your config_model
                
$config $this->config_model->getConfig();
        }


after that, $config can be accessible by a $this->config if your controller extend MY_Controller and not CI_Controller

i'm agree with josepostiga. "DON'T TOUCH THE SYSTEM'S FOLDER !!!!!" Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB