make the config smart base on environment |
[eluser]newtonianb[/eluser]
I have several fields in config.php, database.php and constants.php that are different when i publish my site to server. How can I make it smart and have it automatically pick the right one based on lets say hostname. I tried if(strpos(base_url(),"localhost") === false) but base_url() isn't working in these files, it actually seems to only work inside database.php What else can I do?
[eluser]CroNiX[/eluser]
[quote author="newtonianb" date="1293259879"]I have several fields in config.php, database.php and constants.php that are different when i publish my site to server. How can I make it smart and have it automatically pick the right one based on lets say hostname. I tried if(strpos(base_url(),"localhost") === false) but base_url() isn't working in these files, it actually seems to only work inside database.php What else can I do?[/quote] In my index.php, at the top, I do: Code: define('LIVESITE', ($_SERVER['HTTP_HOST'] === strtolower('www.yoursite.com')) ? TRUE : FALSE); Code: if(LIVESITE) Code: $db['default']['username'] = (LIVESITE) ? 'the_live_site_username' : 'the_dev_site_username';
[eluser]newtonianb[/eluser]
fantastic! thanks alot! last question how can I access $config['base_url'] from constants.php?
[eluser]CroNiX[/eluser]
echo base_url(); should work load the url helper http://ellislab.com/codeigniter/user-gui...elper.html
[eluser]CroNiX[/eluser]
Although I'm not sure if that is accessible yet at that point. Try it. You can always make a custom helper with your code and autoload that (with your custom define statements) |
Welcome Guest, Not a member yet? Register Sign In |