[英]Symfony 3 access entity manager from another bundle`s repository
在我的項目中,我有2個捆綁包(AppBundle和CommonBundle)和2個不同的數據庫,每個捆綁包1個。 在我的配置中顯示如下:
orm:
default_entity_manager: default
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
connection: default
auto_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore
common:
connection: common_data
auto_mapping: false
mappings:
CommonBundle: ~
#FOSUserBundle: ~
naming_strategy: doctrine.orm.naming_strategy.underscore
現在,我位於CommonBundle
的存儲庫中,我想訪問AppBundle
的連接以從其數據庫中獲取一些數據,如下所示:
<?php
namespace CommonBundle\Repository;
use Doctrine\ORM\EntityRepository;
use CommonBundle\Entity\Audit;
class AuditRepository extends EntityRepository
{
public function MyFunc()
{
$em =$this->getEntityManager();
$em_def =$this->getEntityManager('default');
$em_def->getRepository('AppBundle:Info')->getInfo('myInfo');//ERROR here
}
}
但是相反,我得到以下錯誤:
Uncaught PHP Exception Doctrine\ORM\ORMException: "Unknown Entity namespace alias 'AppBundle'." at ...
因此,歡迎提出任何解決方法。 謝謝。
您需要使用完整路徑,因為您在另一個捆綁包中,嘗試使用此路徑或與完整路徑類似的方法:
$em_def->getRepository('AppBundle\Entity\Info')->getInfo('myInfo');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.