Php Symfony 1.4-条令-自定义插件-未知连接

Php Symfony 1.4-条令-自定义插件-未知连接,php,symfony1,symfony-1.4,Php,Symfony1,Symfony 1.4,我正在构建一个自定义插件,它由我试图与插件紧密耦合的模式组成。例如,我有一个plugins/userPlugin/config/doctor/schema.yml,它引用了一个“store rw user”连接。我的目标是强制项目的databases.yml包含“store rw user”的连接,这样项目将负责建立单独的用户连接 然而,当我尝试访问插件相关的代码时,我不断得到:doctor\u Manager\u异常未知连接:store rw user 以下是插件模式文件的相关片段: # pl

我正在构建一个自定义插件,它由我试图与插件紧密耦合的模式组成。例如,我有一个plugins/userPlugin/config/doctor/schema.yml,它引用了一个“store rw user”连接。我的目标是强制项目的databases.yml包含“store rw user”的连接,这样项目将负责建立单独的用户连接

然而,当我尝试访问插件相关的代码时,我不断得到:
doctor\u Manager\u异常未知连接:store rw user

以下是插件模式文件的相关片段:

# plugins/userPlugin/config/doctrine/schema.yml
connection: store-rw-user

User:
  tableName: user
  actAs: [Timestampable]    
# config/databases.yml
all:
  store-rw-user:
    class: sfDoctrineDatabase
    param:
    ....
下面是BaseUser.class.php的相关片段(在进行模型构建时生成):

从一开始,一切看起来都配置正确。plugin schema.yml导致基类绑定正确的数据库连接,该连接存在于项目的databases.yml文件中。然而,我遇到了上述问题。在我开始尝试通过plugins initialize()方法手动操作doctrine connection manager之前,我想知道是否有其他方法可以解决这个问题

--更新--

经过进一步调查,sfDatabaseManager似乎知道“store rw user”连接,但Doctrine_Manager不知道。起初,我认为这可能是由于我在主项目配置文件中添加插件的顺序造成的,但这只会影响sfDatabaseManager是否具有连接感知功能,但为了完整起见,以下是项目配置文件的片段:

// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
    ....

    public function setup()
    {
        ....

        $this->enablePlugins(
            array(
                'sfDoctrinePlugin',
                'userPlugin'
            )
        );
    }
}
为了以防万一,这里是userPlugin的app.yml:

# plugins/userPlugin/config/app.yml
# This entry was needed so build-model was executed, the plugin schema file would be pulled in for build as well
all:
  userPlugin:
    config_dir: %SF_PLUGINS_DIR%/userPlugin/config
    recursive: true
下面是令人困惑的代码片段,我可以通过sfDatabaseManager而不是Doctrine_Manager访问“store rw user”连接,这是一个问题,因为错误是从Doctrine_Manager而不是sfDatabaseManager引发的:

// plugins/userPlugin/config/userPluginConfiguration.class.php
class userPluginConfiguration extends sfPluginConfiguration
{
    public function initialize()
    {
        parent::initialize();

        var_dump(Doctrine_Manager::getInstance()->getConnections());

        $config = ProjectConfiguration::getActive();

        $manager = new sfDatabaseManager($config);

        var_dump($manager->getDatabase('store-rw-user'));

        exit;
    }
}
结果是:

array (size=0)
  empty

object(sfDoctrineDatabase)[53]
  protected '_doctrineConnection' => 
    object(Doctrine_Connection_Mysql)[55]
      protected 'driverName' => string 'Mysql' (length=5)
      protected 'dbh' => null
      protected 'tables' => 
        array (size=0)
          empty
      protected '_name' => string 'store-rw-user' (length=13)
....

不确定发生了什么,尝试查看其他插件,看看它们是如何处理的,但它们没有我可以找到的任何数据库引用。

在添加一些调试代码以选择源文件(Doctrine_Manager)后,我终于在上面initialize()方法中的代码片段中看到,通过简单地配置sfDatabaseManager,随后,条令意识到了这种联系。简而言之,我的方法最终是这样的:

class userPluginConfiguration extends sfPluginConfiguration
{
    public function initialize()
    {
        parent::initialize();

        // Don't ask me why, without this the needed db connection never gets initialized and plugin craps out
        $manager = new sfDatabaseManager(ProjectConfiguration::getActive());
    }
}

而且,神奇的是,条令现在知道了项目的databases.yml文件中的所有连接。在我看来,我必须明确地打这个电话似乎很弱,但至少我可以继续进行一些编码。

您的数据库中没有缩进错误。yml:
store rw user
处于同一级别。这是您的问题中的一个打字错误,还是您的数据库.yml中的一个打字错误?很好,这只是问题中的格式错误,databases.yml的间距正确。
class userPluginConfiguration extends sfPluginConfiguration
{
    public function initialize()
    {
        parent::initialize();

        // Don't ask me why, without this the needed db connection never gets initialized and plugin craps out
        $manager = new sfDatabaseManager(ProjectConfiguration::getActive());
    }
}