Codeigniter: Custom config or constant?
I have some global settings variables I need to store for my application, but I'm confused as to whethe开发者_开发知识库r 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?
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');
精彩评论