简体   繁体   English

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

[英]Loading configuration items from another config file in CI

I've been trying to load a configuration item into another configuration file for my CodeIgniter app. 我一直在尝试将配置项目加载到CodeIgniter应用程序的另一个配置文件中。 The reason for doing this is that I don't want to go through all of the files to change same parameters when I, for example, change the server or want to change the site title. 这样做的原因是,例如,当我更改服务器或想要更改站点标题时,我不想遍历所有文件来更改相同的参数。

I've tried to get the items I need from the main config.php file by using $this->config['site_title'] , by loading the config file using $this->config->load('config') and by loading individual config item using $this->config->item('site_title') but all of these methods return errors that the configuration items could not be loaded. 我试图通过使用$this->config['site_title']从主config.php文件中获取所需的项目,通过使用$this->config->load('config')加载配置文件,并通过使用$this->config->item('site_title')加载单个配置项,但是所有这些方法都返回无法加载配置项的错误。

Am I missing something? 我想念什么吗?

您应该从Controller中的CI实例加载配置文件

$ci = & get_instance();

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

simply create your config file in your ci config folder 只需在ci config文件夹中创建您的配置文件

myconfig.php

in it 在里面

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

and load your config in the controller 并将配置加载到控制器中

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

then get your value 然后得到你的价值

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM