我有一個可以在兩種不同的上下文中瀏覽的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');
所以我問:你會如何實現這個解決方案?
對不起改變app.yml值,但我不明白你的意思。你能更明確嗎? – Gregoire 2012-01-06 10:19:44
@Gregoire對不起,以便延遲迴復。我已經更新了答案。 – Arasu 2012-01-07 04:47:00
就像我說的,問題是我的preExecute中的「bindComponent()」調用被自動加載器覆蓋。 – Gregoire 2012-01-07 09:20:30