2012-01-02 168 views

回答

3

不需要。您需要將此邏輯包含在偵聽器的頂部。這是典型的instanceof檢查:

public function prePersist($eventArgs) 
{ 
    // i.e. using the MongoDB ODM 
    $doc = $eventArgs->getDocument(); 
    if (!$doc instanceof MyModel) { 
     return; 
    } 
} 
+0

這似乎是一種浪費,不是嗎?因爲當我只需要一個實體時,它就會在每個實體上被調用。 – DavidW 2012-01-02 15:40:12

+0

增加這種上游邏輯只會增加複雜性,而不會帶來真正的性能增益。 – 2012-01-02 15:45:48

+0

好的,謝謝克里斯。 – DavidW 2012-01-02 15:52:27

0

由於學說2.4,你可以使用Entity listeners,他們被稱爲僅針對特定的實體類型。

相關問題