9

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.

2 Answers 2

12

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

$config = $this->config->config;
Sign up to request clarification or add additional context in comments.

3 Comments

thank you very much Joseph , but this give me that data in main config.php .. I want to use data that in my custom file (my_config.php) ? thanks again ( I'm trying to get it by myself right now )
aha , sorry joseph I did not notice .. I get all data that in config.php and in my_config.php .. it's very nice now , thanks again :)
Something to note, if you want a certain config file you would do: $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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.