Step 12c: Integration with FOSUserBundle

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

缺省状态下,投票是匿名的。FOSUserBundle认证可以用来标识投票。


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.

为了添加投票用户,Vote类需要实现​​SignedVoteInterface​​接口并添加一个字段到您的映射中。


For example in the ORM:

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​​.

​第12步:启用投票​​。