如何在服务Symfony 4中使用多实体管理器

时间:2018-07-18 07:51:35

标签: symfony doctrine

我在doctrine.yml中设置了两个实体经理 我必须将存储库注入服务,但是问题是存储库始终采用默认的实体管理器。 如何将特定的实体管理器提供给存储库。 在symfony 4中,我们可以使用ServiceEntityRepository

将存储库视为服务

2 个答案:

答案 0 :(得分:2)

您可以尝试将Doctrine\Common\Persistence\ManagerRegistry注入您的构造中。然后使用$managerRegistry->getManager('your_connection_name');

例如:

//use Doctrine\Common\Persistence\ManagerRegistry;
private $connection;
function __construct(ManagerRegistry $em)
{
    $this->connection = $em->getManager('your_connection_name');
}

答案 1 :(得分:1)

您需要将它们分别设置为命名服务,并将其 Range("i10").Copy Range("K22") Range("K22").Interior.ColorIndex = 4 Ws.Cells(22, 11).Borders.LineStyle = XlLineStyle.xlContinuous ElseIf Range("i10") <> "" And Range("K22").Value > 0.5 Then Range("i10").Copy Range("K22") Range("K22").Interior.ColorIndex = 3 Ws.Cells(22, 11).Borders.LineStyle = XlLineStyle.xlContinuous Else If Range("i10") <> "" And Range("i10").Value > 0.25 And Range("i10").Value <= 0.5 Then Range("i10").Copy Range("K22") Range("K22").Interior.ColorIndex = 6 Ws.Cells(22, 11).Borders.LineStyle = XlLineStyle.xlContinuous End If End If 设置为services.yaml文件,而不是延迟/自动加载它们。