我希望为本地/开发/生产配置文件的单独副本,但不要让它们相互干扰并且可能能够在版本控制中共存。
这个问题的优雅解决方案是什么?
最佳答案
试试这个:
<?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!
关于php - 在 PHP 项目中管理本地/开发/生产配置文件的简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18672997/