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 ...
どのように修正するかは歓迎します。ありがとうございました。
'クラスのAppBundle \\エンティティ\\情報」を次のエラーを取得チェーン構成の名前空間CommonBundle \\ Entity at ... 'に見つかりませんでした。 'AppBundle'ではなく' CommonBundle'を検索しています – Masha
いいえ。近くにさえ私は恐れている。 Doctrineリポジトリは、自身のエンティティマネージャのみを知っています。他のマネージャーへの組み込みアクセスはありません。この種のものを動作させるには、かなり複雑な注入が必要です。努力する価値はありません。 – Cerad
CommonBundleの前にあなたの設定にAppBundleを追加してみてください – Mocrates