FOSCommentBundle功能包:设置Doctrine ODM映射(投票)
原文出处: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映射(投票)相关推荐
- FOSCommentBundle功能包:设置Doctrine ODM映射
Step 2b: Setup MongoDB mapping The MongoDB implementation does not provide a concrete Comment class ...
- FOSCommentBundle功能包:添加Symfony2内建的ACL安全
原文出处:8-adding_symfony2s_builtin_acl_security.md 原文作者:FriendsOfSymfony 授权许可:创作共用协议 翻译人员:FireHare 校对人员 ...
- FOSCommentBundle功能包:改变样式
Step 5: Style it This bundle supplies some basic CSS markup that will make it usable. It's included ...
- FOSCommentBundle功能包:基于ACL安全添加角色
注意: This bundle ships with support different security setups. You can also have a look at Adding Sym ...
- FOSCommentBundle功能包:与FOSUserBundle集成
原文出处:6-integration_with_fosuserbundle.md 原文作者:FriendsOfSymfony 授权许可:创作共用协议 翻译人员:FireHare 校对人员: 适用版本: ...
- 【RK3399Pro学习笔记】四、ROS 创建工作空间与功能包
目录 创建工作空间 编译工作空间 功能包 创建功能包 编译功能包 设置环境变量 检查环境变量 平台:华硕 Thinker Edge R 瑞芯微 RK3399Pro 固件版本:Tinker_Edge_R ...
- 图形化解决Ubuntu18.04、16.04无线网卡设置静态IP且能上网。笔记本ssh连接工控机,工控机利用有线网口接激光雷达等传感器、利用无线网口上网下载安装更新功能包
问题描述: 当在工控机上使用ubuntu18.04进行ROS控制时,我们经常需要将工控机与激光雷达通过网线连接,同时我们的工控机可能还配置了无线网卡用来连接因特网(用来浏览网页或者下载安装因特网上的各 ...
- ROS系统 创建工作空间与功能包
ROS 学习目标: 学习内容: 使用环境 操作步骤: 基本命令 二.使用步骤 创建工作空间 编译工作空间 创建功能包 使用C++执行程序 编写源文件 编辑功能包下的 Cmakelist.txt文件 修 ...
- 未能加载包studio package_SLAM组合拳之七 — 创建自定义Gazebo功能包(二)
黄先森 86 180-3110-3700 上一节我们讲解了如何从零开始编写一个简单的URDF文件用于产生TF树,然后讲解了如何对简单的URDF文件进行补充扩展来满足Gazebo仿真包的需要,但我们还是 ...
最新文章
- C++理解全局变量在调用函数中的应用
- 大数据分析中国冬季重度雾霾的成因(三)
- Python获取本地mac地址、主机名、IP地址
- 程序员微信头像_这才是程序员的内心独白
- AAAI 2020 | NAS+目标检测:AI设计的目标检测模型长啥样?
- is not in the sudoers file 解决(转)
- linux重装hal服务安装,linux ubuntu 安装微信客户端
- layuiajax提交表单控制层代码_Ninja Forms:免费的联系表单插件,却提供了付费表单才有的功能【视频+图文】...
- 转:Java NIO系列教程(一)Java NIO 概述
- 【闲聊产品】之一:半路出家的产品经理
- 替换字符串中全部斜杠
- Maven项目中非resources文件夹中的配置文件不生效的解决办法
- Pandas日期时间格式化
- java声音变音代码实现_大话音频变声原理 附简单示例代码
- 设置esxi主机时间
- SSD固态硬盘优化教程
- ps Adobe 存储为 Web 所用格式
- 菜鸟、大牛和教主,三者的区别
- Python模块管理的入门详解,初学者福利
- 天行健,君子以自强不息.