![]() |
Switch between local and live
I believe that many people will comment and uncomment blocks (or individual lines) of code when switching between local and live running of their pages. This can be a pain. I use the following code and just change a value from true to false when moving to the remote/live site:
PHP Code:
|
Here's a cool way of doing it too:
//in your php config file PHP Code:
Code:
|
Not that andrew's way isnt awesome! Just chipping in.
|
Is APPLICATION_ENV specific to certain frameworks or servers? But I suppose it can be assigned in any comparable settings file.
|
Its a bit hitched from the Zend Framework.
Its not specific to any particular framework or server. (I suppose you would have to have apache and use virtualhosting) Whats really cool about this system, is you can chain settings. EG: Developer setting_1 = x setting_2 = y setting_3 = z Developer : Developer_1 setting_3 = a setting_4 = i So setting something like, APPLICATION_ENV = Developer_1, you can then chain settings and use inheritance. Like css I suppose. Of course, you have to write the logic for all that. Its also worth taking a look at how big frameworks etc handle their settings. I really like the zend framework approach, which is why I hacked off its setting system. |
I see my idea has been copied :rolleyes:
http://www.codingforums.com/showthread.php?t=247091 Use the $_SERVER['HTTP_HOST'] to determine which system your script is running on. That way you don't even need to set anything to true or false, no constants to define etc. Just upload all your files (including your mysql config file with no changes for once) and it'll just work straight away. It supports various names / domains for each server (handy if you have subdomains) and can be adjusted for mysqli if needed: PHP Code:
PHP Code:
|
Quote:
|
You're right, it's better - no need to tell it what server your on as it picks the correct SQL credentials automatically :cool:
No need to manually adjust a define statement, no need to change anything really, just upload everything and you're done :) (You can probably tell I like automation lol) The only thing mine won't do is work with cron (for obvious reasons being that there is no domain supplied by a http header). That should be relatively easy to overcome though - you could change the script to work from a machine name instead in the $_SERVER array. |
Quote:
|
lol ;)
|
| All times are GMT +1. The time now is 11:04 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.