我已经设置了两个实体管理器,doctrine.yml
我必须将存储库注入服务,但问题是存储库始终采用默认实体管理器。我应该如何将特定的实体管理器提供给存储库。在 symfony 4 中,我们可以将存储库视为服务使用ServiceEntityRepository
您可以尝试注入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');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1778 次 |
| 最近记录: |