我在 symfony 2.0 中实现了多个数据库概念。现在我需要在依赖注入的概念中动态获取 myservice.php 文件中的实体管理器。我怎么称呼这个实体经理?
服务.xml:
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com /schema/dic/services/services-1.0.xsd">
<services>
<service id="my_service" class="Traxcrm\SalesBundle\Services\MyService">
<argument type="service" id="doctrine" />
</service>
</services>
</container>
我的服务.php
class MyService {
private $doctrine;
public function __construct(Doctrine\Bundle\DoctrineBundle\Registry $doctrine)
{
$this->doctrine = $doctrine;
}
class MyService {
private $doctrine;
public function __construct(Doctrine\Bundle\DoctrineBundle\Registry $doctrine) {
$this->doctrine = $doctrine;
}
public function getUserDetails($id) {
$query = $this->doctrine->getEntityManager('Test')->createQuery("SELECT p FROM TraxcrmSigninBundle:Tblallusers p where p.id=$id");
$userDetails = $query->getArrayResult();
return $userDetails;
}