How to inspect/access config values specified in config/email.php? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How to inspect/access config values specified in config/email.php? (/showthread.php?tid=1674) |
How to inspect/access config values specified in config/email.php? - sneakyimp - 03-31-2015 I'm following the directions here which describe how to configure one's email preferences in a configuration file rather than having to call the initialize method of the Email class. I'm wondering how I might access these configuration values in the email.php file from within a controller? The reason I ask is because I'd like to add some additional configuration values like a default_from address, some kind of server identifier so that I know whether incoming emails are from production vs. dev, etc. Can someone tell me how to access email-related configuration values inside a controller? RE: How to inspect/access config values specified in config/email.php? - CroNiX - 03-31-2015 The docs you linked to say that if you name the config file /config/email.php, that it will use it automatically. Quote:If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() method if you save your preferences in a config file. RE: How to inspect/access config values specified in config/email.php? - RobertSF - 03-31-2015 (03-31-2015, 03:34 PM)sneakyimp Wrote: Can someone tell me how to access email-related configuration values inside a controller? From a few quick experiments that I did, it seems that config is one big object, whether the configuration items are about email, urls, or whatever. You should be able to retrieve them with $this->config->item('item name'); As far as adding items to the config object, I don't find a function that does that, but adding them to the config file will probably include them in the object. RE: How to inspect/access config values specified in config/email.php? - sneakyimp - 03-31-2015 (03-31-2015, 03:54 PM)CroNiX Wrote: The docs you linked to say that if you name the config file /config/email.php, that it will use it automatically.This doesn't solve my problem. As I described in my original post, I need to a) inspect existing values and b) add new/extra values that are not part of the default configuration values. (03-31-2015, 03:59 PM)RobertSF Wrote: From a few quick experiments that I did, it seems that config is one big object, whether the configuration items are about email, urls, or whatever. You should be able to retrieve them with $this->config->item('item name');In my experiments, this is not the case at all. I put this in config/email.php Code: $config["blarg"] = "DISCRETION IS THE BETTER PART OF VALOR"; Code: $blarg = $this->config->item("blarg"); Code: NULL a) the main config file is cluttered and complicated with all of the comments and wide-ranging settings b) the email configuration file is where I want to store all email-related configuration values (like default FROM information, etc.) c) the email configuration will vary locally by server (workstation vs. dev vs. production) so I am excluding email.php from my git repository. this is also avantageous because I want to keep sensitive email credentials out of my github repo. RE: How to inspect/access config values specified in config/email.php? - ivantcholakov - 03-31-2015 $email_config = $this->config->load('email', true, true); RE: How to inspect/access config values specified in config/email.php? - RobertSF - 03-31-2015 Ooops, sorry I misled you. ivantcholakov is right. $this->config->load('email', true, true); will load the $config variables in config/email.php. However, there's still more to do. The first true in the statement makes CI keep the variables separate, so in the $config array they are in their own email array. To retrieve individual values, you must do something like this. PHP Code: $this->config->load('email', true, true); RE: How to inspect/access config values specified in config/email.php? - sneakyimp - 04-01-2015 Thanks for your responses. (03-31-2015, 05:12 PM)ivantcholakov Wrote: $email_config = $this->config->load('email', true, true);In this case, $email_config would be a boolean TRUE if a config file was found and loaded and FALSE if no email config was found/loaded. (03-31-2015, 06:28 PM)RobertSF Wrote:This does work, although it is a bit verbose just to get a config value. RE: How to inspect/access config values specified in config/email.php? - mwhitney - 04-01-2015 Once you've loaded the email config as previously noted, you should also be able to check the individual settings using $this->config->item($var, 'email'); where $var is the setting you wish to check within the email configuration. RE: How to inspect/access config values specified in config/email.php? - RobertSF - 04-01-2015 (04-01-2015, 09:08 AM)sneakyimp Wrote: This does work, although it is a bit verbose just to get a config value. I later thought that you could extend the library. That way, you could include your own values plus setter and getter functions. You'd have all the functionality of the email library plus whatever you added. |