CodeIgniter 获取配置元素

从配置文件中检索元素,使用下面的函数:$this->config->item('item name');其中 item name 是 $config 数组中你期望检索的索引. 例如,要获得您选择的语言,你可以这样做:$lang = $this->config->item('language');当试图获取的元素不存在时,此函数返回 FALSE (boolean) 。
如果你为了用具体的索引来声明配置数组(避免上述索引重名问题)而在函数 $this->config->load 中使用了第二个参数,你可以通过指定函数 $this->config->item() 的第二个参数为特定索引名来获取相关的配置元素。例如:[code]// 载入一个名为 blog_settings.php 的配置文件,然后把它声明为一个索引为 “blog_settings” 的数组
$this->config->load(‘blog_settings’, TRUE);

// 在数组 blog_settings 中获取名为 site_name 的配置元素
$site_name = $this->config->item(‘site_name’, ‘blog_settings’);

// 另外一种方式:
$blog_config = $this->config->item(‘blog_settings’);
$site_name = $blog_config[‘site_name’];[/code]文章来源:http://cwiki.ossez.com/pages/viewpage.action?pageId=2392143