从CI中的另一个配置文件加载配置项


Loading configuration items from another config file in CI

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

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

我错过了什么吗?

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

$ci = & get_instance();

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

在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');