CodeIgniter Forums
Add to global $config array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Add to global $config array (/showthread.php?tid=19151)



Add to global $config array - El Forum - 05-29-2009

[eluser]CrazyMerlin[/eluser]
Hey guys!

How would I add to the global config array?
I have an email config file and would like to add some default values in it so I can pick them up using $this->email->etc etc

Can it be done?

Thanks
Paul.


Add to global $config array - El Forum - 05-29-2009

[eluser]TheFuzzy0ne[/eluser]
You can create another config file and access that via the config library, or you can just stick the data in your config.php file:
Code:
$config['email_settings'] = array(
        'protocol' => 'sendmail',
        'mailpath' => '/usr/sbin/sendmail',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
    );

Then you can grab the array like this:
Code:
$email_config = $this->config->item('email_settings');



Add to global $config array - El Forum - 05-29-2009

[eluser]CrazyMerlin[/eluser]
Thanks man, that'll do it!


Add to global $config array - El Forum - 05-29-2012

[eluser]Webnet[/eluser]
I wish CI had a way to call array items using config->item().... something like
Code:
config->item('email_settings.protocol')



Add to global $config array - El Forum - 05-29-2012

[eluser]InsiteFX[/eluser]
It does if you read.

CodeIgniter Users Guide - Config Class



Add to global $config array - El Forum - 05-29-2012

[eluser]Webnet[/eluser]
I've read through that and I see no examples that require more than a single tier of nested array. It also appears to require the tier be named after the file.


Add to global $config array - El Forum - 05-29-2012

[eluser]Aken[/eluser]
You can always extend the class and make it do whatever you want.