如何使用$ this-> config-> item CODEIGNITER从数组中只调用一个项目?

时间:2013-08-06 16:45:03

标签: codeigniter config

我的配置目录中有一个默认配置文件(default.php)。我已经用自动加载文件加载了它:

$autoload['config'] = array('default');

有我的default.php:

<?php

//$config['secretUserHashKey'] = 'g81h6JH18kASPkgAW16jS132sa186h1';
//$config['secretPhotoNameHashKey'] = 'ghOH3Hs841s98sssp1AHDWPfMHAjd';

// Pages

$config['pagesUrl'] = array(
    'home' => 'homepage',
    'login' => 'loginsite'
);

以及如何在我的观点中使用它?

<li><a href="<?=base_url($this->config->item('home'));?>">Home</a> <span class="divider">/</span></li>

通过这个例子,如果我的字符串是非数组,我可以得到值:

$config['home'] = 'homepage';

那么我该如何从数组中获取项目?

4 个答案:

答案 0 :(得分:8)

试试这个:

<?php echo $this->config->item('home', 'pagesUrl');?>

答案 1 :(得分:2)

我更喜欢这种方式:

$api_config = ci()->config->item('api');
if (isset($api_config['api_server']))
...

或在你的情况下:

$pagesUrl_config = ci()->config->item('pagesUrl');
if (isset(pagesUrl['home']))
...

或在视图中:

<?= @base_url(@ci()->config->item('pagesUrl')['home'])?>

答案 2 :(得分:0)

这应该可以解决问题

 $this->config->config['pagesUrl']['home']

答案 3 :(得分:0)

$ this-> config-> item('item_name');

https://www.codeigniter.com/userguide3/libraries/config.html

相关问题