確かに良い方法が必要ですが、sfDatabaseManagerからDSNを取得することができます。
$appConfig= ProjectConfiguration::getApplicationConfiguration(sfConfig::get('sf_app'), sfConfig::get('sf_env'), false);
$dbManager= new sfDatabaseManagerExt($appConfig);
$dsn=$dbManager->getDsn('doctrine');
:私は、適切な方法を見つけるまで、だから、私は特定の接続と環境のためのデータベース名を取得する必要があるモデルに続いて、次のgetDsn方法
class sfDatabaseManagerExt extends sfDatabaseManager
{
public function getDsn($conn)
{
$db = $this->getDatabase($conn);
$dsn = $db->getParameter('dsn');
return $dsn;
}
}
を追加するsfDatabaseManagerを拡張しました
dbnameを取得するには、dsnを/ regexする必要があります。
誰かが私にこのゴミがどのようにあるのかを教えてもらえればそれは大好きですが、もちろんもっと良い解決策がある場合に限ります。
$oCurrentConnection = Doctrine_Manager::getInstance()->getCurrentConnection();
$sdsn = $oCurrentConnection->getOption('dsn');
私たちは複数のデータベースに、生のSQLクエリを送信しようとしている場合ことを追加したい:私は
http://stackoverflow.com/questions/2837659/in-symfony-1-2-how-can-i-get-the-current-database-name-from-the-database-yml-file –
Iそれを見ましたが、Doctrine_Manager :: getInstance()の全体でpreg_matchよりも洗練された方法があることを期待していました – petesiss
DoctrineManagerが持つものはすべてここにあります:http://www.tig12。net/downloads/apidocs/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Doctrine_Manager.class.html –