Welcome Guest, Not a member yet? Register   Sign In
make the config smart base on environment
#1

[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?
#2

[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);
Then, globally, you can:
Code:
if(LIVESITE)
{
    //something for the live site
}
else
{
    //something for your dev site
}
I also use it to define all of my config database setting and other variables, such as base_url based upon that setting.
Code:
$db['default']['username'] = (LIVESITE) ? 'the_live_site_username' : 'the_dev_site_username';
$db['default']['password'] = (LIVESITE) ? 'the_live_site_password' : 'the_dev_site_password';
#3

[eluser]newtonianb[/eluser]
fantastic! thanks alot!
last question how can I access $config['base_url'] from constants.php?
#4

[eluser]CroNiX[/eluser]
echo base_url(); should work

load the url helper

http://ellislab.com/codeigniter/user-gui...elper.html
#5

[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)




Theme © iAndrew 2016 - Forum software by © MyBB