How can I change config file path in Codeigniter?

你。 提交于 2019-12-23 18:20:27

问题


I use Codeigniter framework , and you know when I try to load a config file then use it

I do something like that :

$this->load->config('myconfig', TRUE); 

myconfig.php file is located inside application folder ( application/config/myconfig.php)

and use it like this :

 $this->config->item('get_item', 'myconfig')

My question is : how can I change the location of myconfig file and use it properly ?

I want to put the config file(s) in out folder like this :

  • mysite -> system(folder)
  • mysite -> user_guide(folder)
  • mysite -> myConfigFiles(folder)
  • mysite -> myConfigFiles(folder) / myconfig.php

I need to do something like this :

$this->load->config(base_url.'myConfigFiles/myconfig', TRUE); 

any help ?


回答1:


Yes - it is possible to do this. The loader will accept ../../relative/paths. You can use a path relative from the default config directory (an absolute path will not work).

So let's say you have this structure (had a hard time following your description):

  • mysite
    • application
      • config <-- default directory
    • system
    • myConfigFiles
      • myconfig.php

You can just do this:

$this->load->config('../../myConfigFiles/myconfig', TRUE);

This works for pretty much everything - views, libraries, models, etc.


Note that with the introduction of the ENVIRONMENT constant in version 2.0.1, you can automatically check for config files within the config directory in another directory that matches the name of the current environment. This is really intended to be a convenience method for loading different files depending on if you are in production or development. I'm not 100% sure what your goals are, but this additional knowledge may also help you achieve them, or it may be totally irrelevant.




回答2:


Really not sure WHY you would want to do this (and I wouldn't recommend it), but since all config files are is regular PHP files you can put a config file in the standard location that loads your extra config files. As an example:

mysite -> application -> config -> myconfigloader.php

then in myconfigloader.php put this:

<?php

require_once(APPPATH.'../myConfigFiles/myconfig.php');

So once you do

$this->load->config('myconfigloader', TRUE); 

It will load everything in your myconfig.php file. Let me know if that works for you.



来源:https://stackoverflow.com/questions/7130234/how-can-i-change-config-file-path-in-codeigniter

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