2011-09-09 32 views
8

我做了很多的搜索我的問題,但我沒有得到任何東西..得到配置文件全陣列笨

在笨,當我使用的配置文件我做到這一點:

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

我的問題是:如何能我得到完整的陣列來處理它?

我想$配置與數組做這樣的事情:

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

和等等..

對不起我的英文破碎!

在此先感謝;)

回答

8

雖然這是無證,並在將來的版本可能會斷裂,您可以通過訪問主配置陣列:

$config = $this->config->config; 
+0

非常感謝你約瑟夫,但是這給了我主要config.php中的數據..我想使用我的自定義文件(my_config.php)中的數據?再次感謝(我試圖自己現在得到它) – Ahmad

+0

啊哈,對不起約瑟夫我沒有注意到..我得到的所有數據,在config.php和my_config.php ..現在非常好,再次感謝: ) – Ahmad

+1

需要注意的是,如果你想要一個特定的配置文件,你應該這樣做:'$ redis = $ this-> config-> config ['redis']' –

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

    echo"<pre>";print_r($my_config); 

它可以幫助你..

0

如果你從Codeigniter的配置文件中獲得多維數組然後 在application/config/config.php中

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

在模型或控制器文件

$變量= $這個 - > config->項( '姓名');

var_dump($ variable);