FOSCommentBundle功能包:与FOSUserBundle集成(投票)

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步:启用投票


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值