• 原文出处:12a-mapping_orm.md

  • 原文作者:FriendsOfSymfony

  • 授权许可:创作共用协议

  • 翻译人员:FireHare

  • 校对人员:

  • 适用版本:FOSCommentBundle 2.0.5

  • 文章状态:草译阶段

Step 12a: Setup Doctrine ORM mapping

The ORM implementation does not provide a concrete Vote class for your use,you must create one. This can be done by extending the abstract entities provided by the bundle and creating the appropriate mappings.

ROM实现并没有提供一个具体的Vote类给您使用,您需要创建一个。这可以通过扩展功能包提供的抽象实体并创建一个相应的映射来实现。

For example:

例如:

 
  

And you should implement VotableCommentInterface in your Comment class and add a field to your mapping:

并且您需要在您的Comment类中实现 VotableCommentInterface 接口,并添加一个字段到您的映射中:

score = $score;
    }
    /**
     * Returns the current score of the comment.
     *
     * @return integer
     */
    public function getScore()
    {
        return $this->score;
    }
    /**
     * Increments the comment score by the provided
     * value.
     *
     * @param integer value
     *
     * @return integer The new comment score
     */
    public function incrementScore($by = 1)
    {
        $this->score += $by;
    }
}

Configure your application

# app/config/config.yml
fos_comment:
    db_driver: orm
    class:
        model:
            vote: MyProject\MyBundle\Entity\Vote


Or if you prefer XML:

如果您偏好XML:

# app/config/config.xml

    
        
    

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

Step 12: Enable voting.

第12步:启用投票。