如何在Codeigniter中更改配置文件路径? [英] How can I change config file path in Codeigniter?

查看:82
本文介绍了如何在Codeigniter中更改配置文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Codeigniter框架,你知道当我尝试加载配置文件,然后使用它



我这样做:

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

myconfig.php文件位于应用程序文件夹(application / config / myconfig.php) >

并使用它:

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

我的问题是:的myconfig文件并正确使用它?



我想将配置文件放在out文件夹中,如下所示:




  • mysite - >系统(资料夹)

  • mysite - > user_guide(资料夹)

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



我需要这样做: / p>

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

任何帮助?

解决方案

是的 - 可以这样做。加载器将接受 ../../ relative / paths 。您可以使用默认配置目录中的相对路径(绝对路径不起作用)。



因此,假设您有这样的结构):



  • mysite

    • b

      • config< - 默认目录


    • 系统

    • myConfigFiles

      • myconfig.php




您可以这样做:

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

这适用于几乎一切 - 视图,库,模型等。






请注意,随着 ENVIRONMENT 常数,您可以在配置目录中自动检查配置文件 在另一个目录中匹配的名称当前环境。这实际上是一个方便的方法加载不同的文件,取决于你是否在生产或开发。我不是100%肯定你的目标是什么,但这些额外的知识也可能帮助你实现它们,或者它可能是完全不相关的。


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.

这篇关于如何在Codeigniter中更改配置文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆