【问题标题】:Loading configuration items from another config file in CI从 CI 中的另一个配置文件加载配置项
【发布时间】:2013-03-22 01:15:48
【问题描述】:

我一直在尝试将配置项加载到我的 CodeIgniter 应用程序的另一个配置文件中。 这样做的原因是我不想通过所有文件来更改相同的参数,例如更改服务器或想要更改站点标题。

我尝试使用 $this->config['site_title'] 从主 config.php 文件中获取我需要的项目,使用 $this->config->load('config') 加载配置文件并使用 $this->config->item('site_title') 加载单个配置项,但所有这些方法返回配置项无法加载的错误。

我错过了什么吗?

【问题讨论】:

  • 要在另一个文件中加载一个文件,你必须使用 include 'file.php' 并直接使用变量,否则我看不到它的工作原理。

标签: php codeigniter configuration


【解决方案1】:

您应该从控制器中的 CI 实例加载配置文件

$ci = & get_instance();

$item_name = $ci->config->item('item_name');

【讨论】:

    【解决方案2】:

    只需在 ci 配置文件夹中创建配置文件

    myconfig.php
    

    在里面

    $config['my_site_title'] = 'TechNew.In - www.technew.in';
    

    并在控制器中加载您的配置

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

    然后得到你的价值

    $my_site_title = $this->config->item('my_site_title');
    

    【讨论】:

    • 配置文件无法加载其他配置文件。
    猜你喜欢
    • 1970-01-01
    • 2014-08-08
    • 2019-04-28
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 2020-07-11
    相关资源
    最近更新 更多