2015-03-02 78 views
-1

在我的應用程序中,我必須允許我的用戶評論兩種實體:食譜和新聞。最佳實踐:Symfony評論

我想知道做這件事的最佳做法是什麼。 評論對象有我在我的評論對象中手動管理的ref_id(整數)和ref(字符串)或我與實體之間的通信接口以及諸如@ManyToMany(targetEntoty =「MyInterfaceHere」)之類的通信接口?

感謝你對你的答案

+0

你想實現什麼?我不明白你的目標。 – 2015-03-02 07:28:32

+0

我希望能夠評論我的食譜和我的新聞。我知道如何通過在Comment類中創建兩個字段(ref_id和ref)來完成此操作。但我認爲這有點愚蠢......我想知道是否有更好的解決方案(比如接口或其他) – 2015-03-02 07:31:34

回答

0

以及良好的執行將是如果食譜,新聞資訊,擴展一個抽象類

use Doctrine\ORM\Mapping\MappedSuperclass; 

/** 
* Abstract base class 
* 
* @MappedSuperclass 
*/ 
abstract class EntityWithComments { 
    /** 
    * 
    *@ORM(many-to-bla) 
    */ 
    private $comments; 
    public function addComment(){...}; 
    public function removeComment(){...}; 
    public function getComments(){...}; 
    ... 

和你的類來擴展它,例如食譜:

class Recipe extends EntityWithComments { ... 

這樣你可以

$recipe->addComment($comment); 
$news->addComment($comment); 

直接...