2013-03-08 12 views
0

我在我的Symfony2.1應用程序中使用自定義UserProvider進行身份驗證。我想用FOSCommentBundle來實施評論。但是當談到簽署評論作者的評論時,我被卡住了。使用FOSCommentBundle時,是否可以使用自定義用戶提供程序簽署評論?

基本上,我有兩個數據庫。我可以從中檢索用戶的憑證(用戶名,鹽,密碼等),但我無法進行任何修改,另一個可用於存儲用戶信息(如她/他的評論(s) )在用戶實體中。

當我使用此用戶實體映射Comment實體時,由於FOSCommentBundle檢索實現UserInterface(在我的安全包中)而不是此用戶實體的實體,因此存在問題。

基本上,有沒有辦法告訴FOSCommentBundle檢索另一個用戶實體,而不是用於身份驗證的實體?

感謝

回答

0

你嘗試FOSUserBundle integration與FOSCommentsBundle?

您需要像這樣實現SignedCommentInterface。

<?php 
// src/MyProject/MyBundle/Entity/Comment.php 

namespace MyProject\MyBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use FOS\CommentBundle\Entity\Comment as BaseComment; 
use FOS\CommentBundle\Model\SignedCommentInterface; 
use Symfony\Component\Security\Core\User\UserInterface; 

/** 
* @ORM\Entity 
*/ 
class Comment extends BaseComment implements SignedCommentInterface 
{ 
    // .. fields 

    /** 
    * Author of the comment 
    * 
    * @ORM\ManyToOne(targetEntity="MyProject\MyBundle\Entity\User") 
    * @var User 
    */ 
    protected $author; 

    public function setAuthor(UserInterface $author) 
    { 
     $this->author = $author; 
    } 

    public function getAuthor() 
    { 
     return $this->author; 
    } 

    public function getAuthorName() 
    { 
     if (null === $this->getAuthor()) { 
      return 'Anonymous'; 
     } 

     return $this->getAuthor()->getUsername(); 
    } 
} 
相關問題