Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter: Custom config or constant?

I have some global settings variables I need to store for my application, but I'm confused as to whether I should use a custom config file or just add new constants to the bottom of the config/constants.php file? These variables won't be changing once set, so are constants the right choice?

What's the difference between the two, and how does Codeigniter handle them?

like image 626
Alex Avatar asked Aug 31 '11 07:08

Alex


1 Answers

Custom config file IMO. That will make your life easier down the line when you decide to upgrade to a new major release of CI, since you'll be able to overwrite config.php without losing critical application constants.

The application-wide config.php is always loaded, so anything you put in there will be globally available, whereas custom config files can be loaded on-demand, saving resources and providing better separation of code responsibilities.

Example: On-demand loading of a config file:

$this->config->load('filename');
like image 53
Jens Roland Avatar answered Sep 25 '22 07:09

Jens Roland