【问题标题】:Is there a simple way to recover the Doctrine Entity Manager from a class name? [duplicate]有没有一种简单的方法可以从类名中恢复 Doctrine Entity Manager? [复制]
【发布时间】:2015-11-20 11:16:55
【问题描述】:

我有一个带有三个原则实体管理器的 Symfony 应用程序,所以我想知道是否有一个网络可以从类名(如 \Company\Bundle\Entity\Classname 相关的实体管理器)中撤销。

到目前为止,我可以使用类似

的方式遍历元数据
$entities = array();
$em = $this->getDoctrine()->getManager('manager_name');
$meta = $em->getMetadataFactory()->getAllMetadata();
foreach ($meta as $m) {
    // Compare classname with $m->getName() and return $em name
}

我正在寻找一种更“优雅”的方式。

【问题讨论】:

  • 你是对的@qooplmao,你的答案就是我 10 分钟前发现的。还是谢谢。

标签: symfony doctrine-orm doctrine


【解决方案1】:

教义ManagerRegistry 有一个方法getManagerForClass。这就是我一直在寻找的。​​p>

【讨论】:

    猜你喜欢
    • 2010-09-24
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 2015-05-16
    • 2011-04-16
    • 2021-03-05
    • 2012-04-04
    • 2022-07-07
    相关资源
    最近更新 更多