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

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()
//Load site settings from DB
$CI =& get_instance();
$settings $CI->model_with_settings_from_database->some_method();
$settings As $key => $val)

What u thinking about that?


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.

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

(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 {

        public function 
// 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

Theme © iAndrew 2016 - Forum software by © MyBB