针对不同环境条件化数据库设置的 Drupal 7 方式是什么?

发布于 2024-10-19 06:57:45 字数 456 浏览 3 评论 0原文

我一直习惯于对 $_SEVER['HTTP_HOST'] 进行测试,然后选择一组不同的设置,如下所示:

 switch ($_SERVER['HTTP_HOST']) {
      case 'prod.myserver.com':
           $database = "settings for prod";
           break;
      case 'stage.myserver.com':
           $database = "settings for staging";
           break;
      case 'dev.myserver.com':
           $database = "settings for dev";
           break;
}

settings.php 中的新设置使其看起来可能有更复杂的设置现在就这样。有没有?

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':
           $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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅笑轻吟梦一曲 2024-10-26 06:57:45

site.php 听起来像您正在寻找的内容

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

,然后您可以创建

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

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

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

最终幸福 2024-10-26 06:57:45

我只使用 Acquia 推荐的格式: 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).
; }

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).
; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文