2017-11-21 10 views
0

私のプロジェクトでは、バンドルごとに2つのバンドル(AppBundleとCommonBundle)と2つの異なるデータベースを取得しました。私の設定では、それは次のように示されています:Symfony 3別のバンドルのリポジトリからのアクセスエンティティマネージャ

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のリポジトリにしていると私はこのように、そのDBから一部のデータを取得するために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 ... 

どのように修正するかは歓迎します。ありがとうございました。

答えて

-1

あなたが別のバンドルにあるので、あなたはこれを試すか、フルパスで似たような 完全なパスを使用する必要があります。

$em_def->getRepository('AppBundle\Entity\Info')->getInfo('myInfo'); 
+0

'クラスのAppBundle \\エンティティ\\情報」を次のエラーを取得チェーン構成の名前空間CommonBundle \\ Entity at ... 'に見つかりませんでした。 'AppBundle'ではなく' CommonBundle'を検索しています – Masha

+0

いいえ。近くにさえ私は恐れている。 Doctrineリポジトリは、自身のエンティティマネージャのみを知っています。他のマネージャーへの組み込みアクセスはありません。この種のものを動作させるには、かなり複雑な注入が必要です。努力する価値はありません。 – Cerad

+0

CommonBundleの前にあなたの設定にAppBundleを追加してみてください – Mocrates

関連する問題