Step 12c: Integration with FOSUserBundle

By default, votes are made anonymously.​​FOSUserBundle​​ authentication can be used to sign the votes.


A) Setup FOSUserBundle(安装FOSUserBundle)

First you have to setup ​​FOSUserBundle​​​. Check the ​​instructions​​.

首先您需要安装 ​​FOSUserBundle​​​。请参阅​​说明​

B) Extend the Vote class(扩展Vote类)

In order to add an author to a vote, the Vote class should implement the ​​SignedVoteInterface​​ and add a field to your mapping.


For example in the ORM:


<?php // src/MyProject/MyBundle/Entity/Vote.php namespace MyProject\MyBundle\Entity; use Doctrine\ORM\Mapping as ORM; use FOS\CommentBundle\Entity\Vote as BaseVote; use FOS\CommentBundle\Model\SignedVoteInterface; use Symfony\Component\Security\Core\User\UserInterface; /**  * @ORM\Entity  */ class Vote extends BaseVote implements SignedVoteInterface {     // .. fields     /**      * Author of the vote      *      * @ORM\ManyToOne(targetEntity="MyProject\MyBundle\Entity\User")      * @var User      */     protected $voter;     /**      * Sets the owner of the vote      *      * @param string $user      */     public function setVoter(UserInterface $voter)     {         $this->voter = $voter;     }     /**      * Gets the owner of the vote      *      * @return UserInterface      */     public function getVoter()     {         return $this->voter;     } }

Back to the main step(返回主步骤)

​Step 12: Enable voting​​.