【问题标题】:get full array from config files in Codeigniter从 Codeigniter 的配置文件中获取完整的数组
【发布时间】:2011-09-09 05:05:15
【问题描述】:

我为我的问题做了很多搜索,但我没有得到任何东西..

在我使用配置文件时,我会在 codeigniter 中这样做:

my_config.php:

$config['my_title'] = ' My Title Here ' ;
$config['color']    = ' red ' ;

我可以这样检索它:

$this->load->config('my_config', TRUE );
$data['my_title'] = $this->config->item('my_title', 'my_config');

我的问题是:我怎样才能得到完整的数组来处理它?

我希望 $config 作为一个数组来做这样的事情:

 foreach($config as $key=>$val){
          $data[$key] = $val ;
        }

所以我不必像这样在配置文件中写入所有变量:

$data['my_title'] = $this->config->item('my_title', 'my_config');
$data['color'] = $this->config->item('color', 'my_config');

等等..

对不起我的英语不好!

提前致谢;)

【问题讨论】:

    标签: codeigniter config


    【解决方案1】:

    虽然这是未记录的,并且可能会在未来的版本中中断,但您可以通过以下方式访问主配置数组:

    $config = $this->config->config;
    

    【讨论】:

    • 非常感谢 Joseph,但这给了我主 config.php 中的数据。我想使用自定义文件 (my_config.php) 中的数据吗?再次感谢(我现在正在尝试自己获取)
    • aha ,抱歉 joseph 我没有注意到 .. 我得到了 config.php 和 my_config.php 中的所有数据 .. 现在非常好,再次感谢 :)
    • 需要注意的是,如果你想要某个配置文件,你会这样做:$redis = $this->config->config['redis']
    【解决方案2】:
        $config=$this->load->config('my_config', TRUE );
        $config = $this->config;
        $my_config=$config->config['my_config'];
    
        echo"<pre>";print_r($my_config);
    

    它可以帮助你..

    【讨论】:

      【解决方案3】:

      如果您从 Codeigniter 的配置文件中获取多维数组 然后 在 application/config/config.php 中

      $config['name']='array_name';

      在模型或控制器文件中

      $variable = $this->config->item('name');

      var_dump($变量);

      【讨论】:

        猜你喜欢
        • 2013-09-08
        • 1970-01-01
        • 2011-06-24
        • 1970-01-01
        • 2015-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多