phparrayscodeigniterconfig

Get full array from config files in CodeIgniter


In CodeIgniter, when I use config files I declare values like this:

my_config.php:

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

Then I can retrieve individual, nominated data like this:

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

My question is: How can I get the full array to deal with it instead of making individual key names?

I want the $config data as an array to do something like this:

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

so that I do not have to write all my variables that in config file like this:

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

Solution

  • While this is undocumented, and might break in future releases, you can access the main config array by:

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