CodeIgniter Forums

Full Version: $this->uri->segment() in config
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
HI it's possible change the database config by $this->uri->segment() :

Code:
$active_group = 'default';
$query_builder = TRUE;

if ($this->uri->segment(1)=='my_domain_1') {

    $db['default'] = array(
        'dsn'    => '',
        'hostname' => 'localhost',
        'username' => '**********',
        'password' => '***********',
        'database' => '***********',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );    
}elseif($this->uri->segment(1)=='my_domain_2'){

    $db['default'] = array(
        'dsn'    => '',
        'hostname' => 'localhost',
        'username' => '********',
        'password' => '********',
        'database' => '********',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );



}


I have this error Message: Using $this when not in object context
$this is a pseudo-variable (also a reserved keyword) which is only available inside methods. And,
it refers to the object of the current method. Which database.php is not an object (Class).