我的 config/database.php 文件包含一个简单的条件,可以根据其所在的服务器交换数据库凭据:
$server = $_SERVER['SERVER_NAME'];
if(($server=='localhost')||($server=='127.0.0.1'))
{
$db['default']['hostname'] = 'MY_LOCAL_IP';
$db['default']['username'] = 'MY_LOCAL_USERNAME';
$db['default']['password'] = 'MY_LOCAL_PASSWORD';
$db['default']['database'] = 'MY_LOCAL_DB';
}
else
{
$db['default']['hostname'] = 'MY_PROD_IP';
$db['default']['username'] = 'MY_PROD_USERNAME';
$db['default']['password'] = 'MY_PROD_PASSWORD';
$db['default']['database'] = 'MY_PROD_DB';
}
我开始使用 Doctrine 中,引起我注意的一件事是命令行界面。该提示可以执行各种操作,其中之一是验证条令是否已正确配置以供生产使用。
但是,当在 CLI 中调用 ensure-Production-settings
时,界面对我大喊大叫,指出 SERVER_NAME 是一个未定义的索引。虽然这不是什么问题,但它让我想到 Doctrine 可能在执行我的应用程序期间在后台默默地抱怨同样的事情。
我想我可以制作两个单独的database.php 文件 - 但在此之前 - 有没有人在更改 config/database.php
后遇到过 Doctrine CLI 的问题?
My config/database.php
file contains a simple conditional that swaps out database credentials based on the server it lives:
$server = $_SERVER['SERVER_NAME'];
if(($server=='localhost')||($server=='127.0.0.1'))
{
$db['default']['hostname'] = 'MY_LOCAL_IP';
$db['default']['username'] = 'MY_LOCAL_USERNAME';
$db['default']['password'] = 'MY_LOCAL_PASSWORD';
$db['default']['database'] = 'MY_LOCAL_DB';
}
else
{
$db['default']['hostname'] = 'MY_PROD_IP';
$db['default']['username'] = 'MY_PROD_USERNAME';
$db['default']['password'] = 'MY_PROD_PASSWORD';
$db['default']['database'] = 'MY_PROD_DB';
}
I started playing around with Doctrine today and one thing that caught my eye was the Command Line Interface. The prompt can do all sorts of things, one of which is verification that doctrine is properly configured for production use.
But when calling ensure-production-settings
in the CLI, the interface yells at me stating that SERVER_NAME is an undefined index. While this isn't much of an issue, it got me thinking that Doctrine might be silently complaining of the same thing in the background during the execution of my application.
I guess I could make two separate database.php files - but before that - has anybody experienced issues with Doctrine CLI after making a change to config/database.php
?
发布评论
评论(2)
那么
$_SERVER['SERVER_NAME']
未在 CLI 模式中设置,因为此信息是由网络服务器的 CGI 接口提供的(或者在使用时由网络服务器本身提供) php 作为一个模块)。为什么不使用 环境 呢?
Well
$_SERVER['SERVER_NAME']
is not set in CLI mode, since this information is provided by the CGI-interface of your webserver (or by the webserver itself when using php as a module).Why don't you use environments for that?
在不破坏您现在所做的事情的情况下,作为执行,您可以为 CLI 定义一个持久值,因为它无法识别某些环境变量...
Without breaking what you did right now, as an execption, you could define a persistent values for CLI since it will not recognized some environment variable...