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示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<?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(返回主步骤)
本文转自 firehare 51CTO博客,原文链接:http://blog.51cto.com/firehare/1259600,如需转载请自行联系原作者