Welcome Guest, Not a member yet? Register   Sign In
$this->uri->segment() in config
#1

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

$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).
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB