Codeigniter: access to configuration variables from other configuration files?

I have two configuration files.

config.php (flammable kernel configuration)

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

What I want to do is this.

In config.php there is

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

then in email.php there is

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 has no effect (im guessing since $ config ['env'] does not have these values).

How do I access this value?

+3
source share
7 answers

I checked at this point in the life cycle of the request, the config property of the CodeIgniter object is just an array, not a configuration object.

, :

$this->config['env']

, :

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
}

, , . , .

+8

.

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

, . , , .

+4

:

 $env = $this->config->item('env');

 if ($env == "dev_server")  {
   // Do this...
 }
 else  {
   // Do this..
 }
+3

  • /Config/ceveloppment/my _config.php
  • ///my_config.php

http://codeigniter.com/user_guide/libraries/config.html

0

config_item (system/core/Common.php)

/** * * * @access public * @

0

.

$this- > config- > [ 'base_url']

echo "<pre>";
print_r($this->config);

0

CodeIgniter 3.0 CodeIgniter. , , , item.

$CI =& get_instance();
$var = $CI->config->item('item_name');
0

Source: https://habr.com/ru/post/1779311/


All Articles