Php Symfony 3从另一个捆绑包的存储库访问实体管理器
在我的项目中,我得到了2个捆绑包(AppBundle和CommonBundle)和2个不同的数据库,每个捆绑包1个。在我的配置中,它如下所示:Php Symfony 3从另一个捆绑包的存储库访问实体管理器,php,symfony,Php,Symfony,在我的项目中,我得到了2个捆绑包(AppBundle和CommonBundle)和2个不同的数据库,每个捆绑包1个。在我的配置中,它如下所示: orm: default_entity_manager: default auto_generate_proxy_classes: "%kernel.debug%" entity_managers: default: connection: default
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
<?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
}
}
现在我在CommonBundle
s存储库中,我想访问AppBundle
s连接以从其数据库中获取一些数据,如下所示:
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
<?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
}
}
因此,任何关于如何修复它的想法都是受欢迎的。多谢各位 您需要使用完整路径,因为您在另一个捆绑包中 使用完整路径尝试以下操作或类似操作:
$em_def->getRepository('AppBundle\Entity\Info')->getInfo('myInfo');
获取以下错误
在位于…
的链配置命名空间CommonBundle\\Entity中找不到类“AppBundle\\Entity\\Info”。它正在搜索CommonBundle
,而不是AppBundle
Nope。恐怕还不太近。条令存储库只知道它自己的实体管理器。没有内置的访问其他经理的权限。这需要一些相当复杂的注射才能使这类事情起作用。不值得这么做。请尝试在CommonBundle之前在配置中添加AppBundle