问题
I've just started to use codeigniter and I have a question.
I am using arrays for defining certain values like:
$gender = array ('male','female');
Or:
$maritalStatus = array ('married', 'single', 'divorced');
I am using these kind of arrays in different views. My question is, is there a chance to put all of these arrays in a configuration file and load it when I need it? Or is there another method to achieve this?
Thanks a lot.
回答1:
Yes, you can. Just place all your variables in an array, and save that array in a separate config file in system/application/config
.
Then, in your application code, load the config file like so:
$this->config->load($config_file);
Where $config_file
is the name of your config file, without the .php
extension.
来源:https://stackoverflow.com/questions/3165596/how-do-i-load-custom-configuration-files-with-codeigniter