make the config smart base on environment - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: make the config smart base on environment (/showthread.php?tid=37044) |
make the config smart base on environment - El Forum - 12-24-2010 [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? make the config smart base on environment - El Forum - 12-24-2010 [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'; make the config smart base on environment - El Forum - 12-24-2010 [eluser]newtonianb[/eluser] fantastic! thanks alot! last question how can I access $config['base_url'] from constants.php? make the config smart base on environment - El Forum - 12-24-2010 [eluser]CroNiX[/eluser] echo base_url(); should work load the url helper http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html make the config smart base on environment - El Forum - 12-24-2010 [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) |