using args[] to tell which server? |
I want to run my app either on the remote server or my localhost. To start it on my localhost I start the Apache and then type localhost in the browser window. To start it on the server I type 54.152.xxx.9/sub_crud on the browser address bar. In my database.cfg I have
if ($_SERVER['DOCUMENT_ROOT']="localhost") { $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => 'xxxx', 'database' => 'substantiator', '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 ); } else { $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' => 'xxxx', 'database' => 'substantiator', '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 also have this in my config.cfg if ($args[0]="localhost") { $config['base_url'] = 'http://localhost//'; } else { $config['base_url']='http://54.152.xxx.9/sub_crud/'; } For some reason, the localhost database seems to always load. It also seems that DOCUMENT_ROOT is unreliable and seems to be set to localhost even though I am using the 54.152.xxx.9/sub_crud in the browser. Is there a better way to do this? The passwords for the databases on the two servers are different.
proof that an old dog can learn new tricks
@richb201,
You could use the application environment feature of CI... (setting environment variable) https://codeigniter.com/user_guide/gener...vironments (setting config variables for specific environments) https://codeigniter.com/user_guide/libra...vironments I use it for development and production environments which are on different servers.
That is a pretty cool thing. I realized that I should have used == instead of =, so I will try that first.
addendum: I am going to try ENVIRONMENT since argc fails. One question, how do I set the ENVIRONMENT? I created a config/testing directory. In it I have a localhost centric config.php and database.php as the docs say to do. I then modified the index.php like this: define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); define ('ENVIRONMENT','testing'); and then I modified a few lines lower to: switch (ENVIRONMENT) { case 'development': case 'testing': error_reporting(-1); // ini_set("error_reporting", E_ALL & ~E_DEPRECATED); //rnb ini_set('display_errors', 1); break; // case 'testing': case 'production': I thought that this would use development, but also use the config/testing config files. But it still uses the regular old config files, instead.
proof that an old dog can learn new tricks
Got it working. I used this code in the index.php
$_SERVER['CI_ENV']='testing'; //define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
proof that an old dog can learn new tricks
|
Welcome Guest, Not a member yet? Register Sign In |