开发者

What's The Drupal 7 Way of conditionalizing database settings for different environments?

I've been in the habit of doing a test of $_SEVER['HTTP_HOST'] and then choosing a different set of settings, like this:

 switch ($_SERVER['HTTP_HOST']) {
      case 'prod.myserver.com':
       开发者_如何学JAVA    $database = "settings for prod";
           break;
      case 'stage.myserver.com':
           $database = "settings for staging";
           break;
      case 'dev.myserver.com':
           $database = "settings for dev";
           break;
}

The new set-up in settings.php makes it look like there might be a more sophisticated way now. Is there?


sites.php sounds like what you are looking for

$sites = array(
  'prod.myserver.com' => 'prod',
  'stage.myserver.com' => 'stage',
  'dev.myserver.com' => 'dev'
);

then you can create

/sites/prod/settings.php
/sites/stage/settings.php
/sites/dev/settings.php

See http://api.drupal.org/api/drupal/sites--example.sites.php/7


I just use the format Acquia recommends: https://docs.acquia.com/cloud-platform/develop/env-variable/#examples

if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
   switch ($_ENV['AH_SITE_ENVIRONMENT']) {
     case 'dev':
       // do something on dev
       break;
     case 'test':
       // do something on staging
       break;
     case 'prod':
       // do something on prod
       // Site Factory may require a different value depending
       // on site configuration
       break;
     case 'ra':
       // do something on ra - necessary if a
       // Remote Administration environment is present
       break;
     }
    }
    else {
    // do something for a non-Acquia-hosted application
    // (like a local dev install).
; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜