2013-03-08 4 views
0

내 Symfony2.1 응용 프로그램에서 인증을 위해 사용자 정의 사용자 프로 바이더를 사용하고 있습니다. FOSCommentBundle을 사용하여 주석을 구현하고 싶습니다. 그러나 코멘트 작성자가 코멘트에 서명 할 때, 나는 붙어있다.FOSCommentBundle을 사용할 때 사용자 정의 사용자 공급자를 사용하여 주석에 서명 할 수 있습니까?

기본적으로 두 개의 데이터베이스가 있습니다. 내가 사용자의 자격 증명 (사용자 이름, 소금, 암호 등)을 검색 할 수는 있지만 수정할 수없는 정보, 사용자 정보를 저장하는 데 사용할 수있는 정보 (예 :)를 사용자 엔터티에 저장합니다.

Comment 엔티티를이 User 엔티티로 매핑 할 때 FOSCommentBundle이 (이 사용자 엔티티가 아닌) UserInterface를 구현하는 엔티티를 검색하므로 문제가 있습니다.

기본적으로 FOSCommentBundle에게 인증에 사용 된 것과 다른 사용자 엔터티를 검색하도록 지시하는 방법이 있습니까?

감사

답변

0

당신이 FOSCommentsBundle와 FOSUserBundle integration을 시도 했습니까?

이와 같이 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(); 
    } 
}