• 原文出处:12b-mapping_mongodb.md

  • 原文作者:FriendsOfSymfony

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

  • 翻译人员:FireHare

  • 校对人员:

  • 适用版本:FOSCommentBundle 2.0.5

  • 文章状态:草译阶段

Step 12b: Setup MongoDB mapping

The MongoDB implementation does not provide a concrete Vote class for your use,you must create one:

ROM实现并没有提供一个具体的Vote类给您使用,您需要创建一个:

<?php
// src/MyProject/MyBundle/Document/Vote.php
namespace MyProject\MyBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use FOS\CommentBundle\Document\Vote as BaseVote;
/*** @MongoDB\Document* @MongoDB\ChangeTrackingPolicy("DEFERRED_EXPLICIT")*/
class Vote extends BaseVote
{/*** @MongoDB\Id*/protected $id;/*** Comment of this vote** @var Comment* @MongoDB\ReferenceOne(targetDocument="MyProject\MyBundle\Document\Comment")*/protected $comment;
}

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

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

<?php
// src/MyProject/MyBundle/Document/Comment.php
namespace MyProject\MyBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use FOS\CommentBundle\Document\Comment as BaseComment;
use FOS\CommentBundle\Model\VotableCommentInterface;
/*** @MongoDB\Document* @MongoDB\ChangeTrackingPolicy("DEFERRED_EXPLICIT")*/
class Comment extends BaseComment implements VotableCommentInterface
{// .. fields/*** @MongoDB\Int* @var int*/protected $score = 0;/*** Sets the score of the comment.** @param integer $score*/public function setScore($score){$this->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(配置您的应用程序)

In YAML:

YAML格式:

# app/config/config.yml
fos_comment:db_driver: mongodbclass:model:vote: MyProject\MyBundle\Document\Vote

Or if you prefer XML:

如果您偏好XML:

# app/config/config.xml
<fos_comment:config db-driver="mongodb"><fos_comment:class><fos_comment:modelvote="MyProject\MyBundle\Document\Vote"/></fos_comment:class>
</fos_comment:config>

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

Step 12: Enable voting.

第12步:启用投票。

转载于:https://blog.51cto.com/firehare/1259410

FOSCommentBundle功能包:设置Doctrine ODM映射(投票)相关推荐

  1. FOSCommentBundle功能包:设置Doctrine ODM映射

    Step 2b: Setup MongoDB mapping The MongoDB implementation does not provide a concrete Comment class ...

  2. FOSCommentBundle功能包:添加Symfony2内建的ACL安全

    原文出处:8-adding_symfony2s_builtin_acl_security.md 原文作者:FriendsOfSymfony 授权许可:创作共用协议 翻译人员:FireHare 校对人员 ...

  3. FOSCommentBundle功能包:改变样式

    Step 5: Style it This bundle supplies some basic CSS markup that will make it usable. It's included ...

  4. FOSCommentBundle功能包:基于ACL安全添加角色

    注意: This bundle ships with support different security setups. You can also have a look at Adding Sym ...

  5. FOSCommentBundle功能包:与FOSUserBundle集成

    原文出处:6-integration_with_fosuserbundle.md 原文作者:FriendsOfSymfony 授权许可:创作共用协议 翻译人员:FireHare 校对人员: 适用版本: ...

  6. 【RK3399Pro学习笔记】四、ROS 创建工作空间与功能包

    目录 创建工作空间 编译工作空间 功能包 创建功能包 编译功能包 设置环境变量 检查环境变量 平台:华硕 Thinker Edge R 瑞芯微 RK3399Pro 固件版本:Tinker_Edge_R ...

  7. 图形化解决Ubuntu18.04、16.04无线网卡设置静态IP且能上网。笔记本ssh连接工控机,工控机利用有线网口接激光雷达等传感器、利用无线网口上网下载安装更新功能包

    问题描述: 当在工控机上使用ubuntu18.04进行ROS控制时,我们经常需要将工控机与激光雷达通过网线连接,同时我们的工控机可能还配置了无线网卡用来连接因特网(用来浏览网页或者下载安装因特网上的各 ...

  8. ROS系统 创建工作空间与功能包

    ROS 学习目标: 学习内容: 使用环境 操作步骤: 基本命令 二.使用步骤 创建工作空间 编译工作空间 创建功能包 使用C++执行程序 编写源文件 编辑功能包下的 Cmakelist.txt文件 修 ...

  9. 未能加载包studio package_SLAM组合拳之七 — 创建自定义Gazebo功能包(二)

    黄先森 86 180-3110-3700 上一节我们讲解了如何从零开始编写一个简单的URDF文件用于产生TF树,然后讲解了如何对简单的URDF文件进行补充扩展来满足Gazebo仿真包的需要,但我们还是 ...

最新文章

  1. C++理解全局变量在调用函数中的应用
  2. 大数据分析中国冬季重度雾霾的成因(三)
  3. Python获取本地mac地址、主机名、IP地址
  4. 程序员微信头像_这才是程序员的内心独白
  5. AAAI 2020 | NAS+目标检测:AI设计的目标检测模型长啥样?
  6. is not in the sudoers file 解决(转)
  7. linux重装hal服务安装,linux ubuntu 安装微信客户端
  8. layuiajax提交表单控制层代码_Ninja Forms:免费的联系表单插件,却提供了付费表单才有的功能【视频+图文】...
  9. 转:Java NIO系列教程(一)Java NIO 概述
  10. 【闲聊产品】之一:半路出家的产品经理
  11. 替换字符串中全部斜杠
  12. Maven项目中非resources文件夹中的配置文件不生效的解决办法
  13. Pandas日期时间格式化
  14. java声音变音代码实现_大话音频变声原理 附简单示例代码
  15. 设置esxi主机时间
  16. SSD固态硬盘优化教程
  17. ps Adobe 存储为 Web 所用格式
  18. 菜鸟、大牛和教主,三者的区别
  19. Python模块管理的入门详解,初学者福利
  20. 天行健,君子以自强不息.

热门文章

  1. docker 系列之 配置阿里云镜像加速器
  2. 怎么让wordpress用sqlite3 搭建轻量级博客系统
  3. 在全面部署 IPV6 前,你需要了解都在这儿
  4. AJAX 一些常用方法
  5. 几种开源工作流引擎的简单比较(转)
  6. 在 ASP.NET 网页中不经过回发而实现客户端回调
  7. Linux文件压缩与解压缩
  8. OCA读书笔记(9) - 管理数据同步
  9. 想挖矿?不如先学习一下以太坊
  10. 在7分钟内深刻理解咖喱