[英]Symfony2 - Two database connections in one bundle - can't seem to set it up - see my code
這就是我想要做的:
namespace BundleTwo\Controller;
use BundleOne\Entity\TestEntity;
class TestController
{
public function pageAction()
{
$insert = new TestEntity();
$insert->fieldName('test');
$em = $this->getDoctrine()->getManager('dbcon2');
$em->persist($insert);
$em->flush();
}
}
…因此,上面的代碼在Bundle 2中,它使用Bundle 1中的Entity-但它需要使用DB connection2。
我可以使用此http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html設置兩個數據庫連接,我可以看到如何定義捆綁使用哪個EM,但是我想要2一捆的連接。
我認為上面的代碼可以工作,但是當我運行app / console doctrine:schema:update --em = dbcon2時,它不會在數據庫中填充任何內容,也不會檢測到任何實體。 我想我需要以某種方式使其意識到BundleOne \\ Entity \\ TestEntity也被Bundle 2和DB 2使用。
如果我可以將設置放在BundleTwo內,該設置可以設置用於BundleOne \\ Entity \\ TestEntity的數據庫連接,則可以這樣做。
您可以指定哪些捆綁包包含具有mapping
屬性的實體元數據
doctrine:
orm:
default_entity_manager: dbcon1
entity_managers:
dbcon1:
connection: dbcon1
mappings:
BundleOne: ~
dbcon2:
connection: dbcon2
mappings:
BundleOne: ~
如您所猜測的,您必須告訴每個實體管理器在尋找實體時要使用哪個捆綁軟件。
就像是:
orm:
default_entity_manager: default
auto_generate_proxy_classes: %kernel.debug%
#auto_mapping: true
entity_managers:
default:
connection: default
mappings:
games:
connection: games
mappings:
CeradGameBundle: ~
accounts:
connection: accounts
mappings:
FOSUserBundle: ~
CeradAccountBundle: ~
因此,您的dbcon2將列出捆綁1和捆綁2。 如果此答案無濟於事,請更新您的問題並顯示您的主義orm配置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.