How do I load custom configuration files with codeigniter?

隐身守侯 提交于 2020-01-04 09:06:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!