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