我有一个 symfony 网站,可以在两种不同的环境中浏览。我的意思是上下文,而不是应用程序(我使用ysfDimensionsPlugin)。在第一个上下文中,我使用绑定到数据库 db1 的 sfGuard 对用户进行身份验证;在第二种情况下,我使用 sfGuard 对用户进行身份验证,但绑定到数据库 db2。
这两个连接在 databases.yml 中定义为标准 sfDoctrineDatabase 对象。在 schema.yml 中,我将 sfGuard 组件绑定到 db1 连接。所以在我的 sfGuard 基类中,我有这个:
Doctrine_Manager::getInstance()->bindComponent('sfGuardUser', 'db1');
如果我在第二个上下文中,我尝试做的是动态地将 sfGuard 组件绑定到 db2 连接。所以在全局 preExecute 方法中,我这样做:
Doctrine_Manager::getInstance()->bindComponent('sfGuardUser', 'db2');
Doctrine_Manager::getInstance()->bindComponent('sfGuardGroup', 'db2');
绑定已完成,但在进行查询时会立即被覆盖:sfAutoload 加载 sfGuard 类,包括基类,调用以下代码:
Doctrine_Manager::getInstance()->bindComponent('sfGuardUser', 'db1');
所以我问:你将如何实现它来解决它?