Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter: access config variables from other config files?

I have two config files.

config.php (code igniters core config)

and email.php (autoloaded by the email class when it is used)

What i am wanting to do is.

In config.php have

$config['env'] = 'hailwood_dev';

then in email.php have

if($config['env'] == 'hailwood_dev'){
//email variables like smtp server to do with localhost
} elseif($config['env'] == 'production'){
//email variables like smtp server to do with production
}

But this is not having any effect (im guessing as $config['env'] does not have those values).

How can I access this value?

like image 288
Hailwood Avatar asked Dec 08 '22 00:12

Hailwood


2 Answers

I checked and at that point in the request lifecycle the config property of the CodeIgniter object is just an array, not a config object.

So you should be able to get at your configuration setting like this :

$this->config['env']

So this should work :

if ($this->config['env'] == 'hailwood_dev')
{
    //email variables like smtp server to do with localhost
} 
elseif ($this->config['env'] == 'production'){
    //email variables like smtp server to do with production
}

If you are autoloading configuration files, make sure they are autoloaded in the correct order. A configuration file must be autoloaded after any it depends on.

like image 122
Stephen Curran Avatar answered Jan 16 '23 15:01

Stephen Curran


Add this to your email config file.

$environment = config_item('env');
OR THIS
$environment = $this->config->item('env');

Not sure if the first will work on your setup. Most people seem to use the second.

like image 37
Anthony Jack Avatar answered Jan 16 '23 14:01

Anthony Jack