php - 在 PHP 项目中管理本地/开发/生产配置文件的简单方法是什么?

标签 php configuration app-config configuration-files conflict

我希望为本地/开发/生产配置文件的单独副本,但不要让它们相互干扰并且可能能够在版本控制中共存。

这个问题的优雅解决方案是什么?

最佳答案

试试这个:

<?php 

// rename this file to whatever your configuration file is supposed to be called (wp-config.php, etc.).

switch ($_SERVER['SERVER_NAME']):

// assuming your local server name is 'localhost,' leave this section alone
    case 'localhost':
        require_once('local.config.php');
        break;

// replace production-url with the server name for your production site
    case 'production-url':
        require_once('production.config.php');
        break;

// replace development-url with the server name for your development site
    case 'development-url':
        require_once('development.config.php');
        break;

    default:
     // something went wrong;

endswitch;
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!

Source

关于php - 在 PHP 项目中管理本地/开发/生产配置文件的简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18672997/

相关文章:

php - 如何递归调用Ajax函数

php - OOP 抽象类何时实现抽象方法

php - Magento - 检查管理员和客户是否登录

c# - 如何在不使用 HttpContext 的情况下获取 Web 应用程序的当前配置?

mysql - 变量 log_bin 值 off - 这意味着什么?

configuration - 在 ASP.NET Core 中的 ConfigureServices 阶段实际读取 AppSettings

javascript - 触发单击单选按钮并记住页面刷新时的选择

.net - 如何将配置文件引入 Powershell 脚本?

.net - 如何调试具有使用app.config文件的.net互操作项目的VB6项目?

python - 在 Emacs 中配置新模式 : installing python-mode. el