1
有没有一种简单的方法从实体的类方法中获取Doctrine的实体管理器?我可以从实体的类方法中获取EntityManager吗?
<?php
/** @Entity */
class MyEntity {
/** @Id @GeneratedValue @Column(type="integer") */
protected $id;
[...]
public function someFunction() {
// Is there any way to get Doctrine's EntityManager in here?
}
}
你不能这样做。你的实体不应该依赖于EntityManager或Repository。 – meze
忘记我之前的评论:你为什么需要在一个实体的EM? – meze
那么,我打算在某些情况下创建并坚持另一个对象,但我想最好在别处创建它。我确实设法通过将它存储在$ GLOBALS中来获得EM,但我会尝试重构。 – Matt