[development] How implement global variables that vary depending on the server (i.e. production, test, demo) within Drupal?
António P. P. Almeida
appa at perusio.net
Fri Mar 18 03:23:11 UTC 2011
On 17 Mar 2011 17h40 WET, mitchelljj98 at gmail.com wrote:
> [1 <text/plain; ISO-8859-1 (7bit)>] For java webapps within Apache
> Tomcat I use a web.xml file which contains the global variables that
> are specific to that server so that the production server will have
> one web.xml file and the test server will have a different web.xml
> file.
>
> How can I do something similar for global variables that vary
> depending on the server (i.e. production, test, demo) within Drupal?
Several ways to do that.
1. There's the approach of using a diferent setting.php with a
conditional inclusion as already described in this thread.
2. There's the approach of using a *single* settings.php file and
instead do the conditional logic inside where you set the global
variables you want. Use drush to activate/deactivate the settings.
drush vset mysite_dev 1
This creates a variable that can be used in a if like:
// Do site specific stuff here.
if (variable_get('mysite_dev', 0)) {
/* do stuff for dev site */
}
You can use drush vdel to delete the variable.
If you want to have a more structured approach create constante like
like this:
define('MYSITE_DEV', 1);
define('MYSITE_STAGE', 2);
define('MYSITE_PROD', 3);
and do:
drush vset mysite_version 1
for making it dev
if (variable_get('mysite_version' 0) == MYSITE_DEV) {
/* do stuff for dev site */
}
and so on for the other versions.
--- appa
More information about the development
mailing list