Welcome Guest, Not a member yet? Register   Sign In
How to inspect/access config values specified in config/email.php?
#1

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?
Reply
#2

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.
Reply
#3

(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.
 
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#4

(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";
And this in a controller:
Code:
        $blarg = $this->config->item("blarg");
        var_dump($blarg);
The output?
Code:
NULL
When I moved that config line to application/config.php, it did show up correctly, but I would like these added config values (which are not part of the standard configuration) to be grouped with the email configuration file because
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.
Reply
#5

$email_config = $this->config->load('email', true, true);
Reply
#6

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'truetrue);
$email_vars $this->config->item('email');
echo 
$email_vars['protocol']; 
That will echo 'sendmail' to the screen.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#7

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:
PHP Code:
$this->config->load('email'truetrue);
$email_vars $this->config->item('email');
echo 
$email_vars['protocol']; 
This does work, although it is a bit verbose just to get a config value.
Reply
#8

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.
Reply
#9

(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.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB