开发者

How can I change config file path in Codeigniter?

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 ?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜