当前位置: 首页 > news >正文

FOSCommentBundle功能包:设置Doctrine ORM映射(投票)

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:

例如:

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
<?php
// src/MyProject/MyBundle/Entity/Vote.php
namespace  MyProject\MyBundle\Entity;
use  Doctrine\ORM\Mapping  as  ORM;
use  FOS\CommentBundle\Entity\Vote  as  BaseVote;
/**
  * @ORM\Entity
  * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
  */
class  Vote  extends  BaseVote
{
     /**
      * @ORM\Id
      * @ORM\Column(type="integer")
      * @ORM\generatedValue(strategy="AUTO")
      */
     protected  $id ;
     /**
      * Comment of this vote
      *
      * @var Comment
      * @ORM\ManyToOne(targetEntity="MyProject\MyBundle\Entity\Comment")
      */
     protected  $comment ;
}

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

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

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
40
41
42
43
44
45
46
47
48
<?php
// src/MyProject/MyBundle/Entity/Comment.php
namespace  MyProject\MyBundle\Entity;
use  Doctrine\ORM\Mapping  as  ORM;
use  FOS\CommentBundle\Entity\Comment  as  BaseComment;
use  FOS\CommentBundle\Model\VotableCommentInterface;
/**
  * @ORM\Entity
  */
class  Comment  extends  BaseComment  implements  VotableCommentInterface
{
     // .. fields
     /**
      * @ORM\Column(type="integer")
      * @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

1
2
3
4
5
6
# app/config/config.yml
fos_comment:
     db_driver: orm
     class :
         model:
             vote: MyProject\MyBundle\Entity\Vote


Or if you prefer XML:

如果您偏好XML:

1
2
3
4
5
6
7
8
# app/config/config.xml
< fos_comment:config  db-driver = "orm" >
     < fos_comment:class >
         < fos_comment:model
             vote = "MyProject\MyBundle\Entity\Vote"
         />
     </ fos_comment:class >
</ fos_comment:config >

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

Step 12: Enable voting.

第12步:启用投票。



本文转自 firehare 51CTO博客,原文链接:http://blog.51cto.com/firehare/1259408,如需转载请自行联系原作者

相关文章:

  • 一个16年毕业生所经历的php面试
  • svn1.5+TortoiseSVN1.5+VisualSVN1.5
  • sed常用
  • sublime配置文件
  • 性能测试之手机号码python生成方式
  • centos7 安装 keepalived
  • nginx访问http80端口跳转https443端口
  • 10.6 监控io性能;10.7 free;10.8 ps;10.9 查看网络状态;10.10 抓包
  • shell $$ 的详解
  • Struts1.x 跨站脚本(XSS)漏洞的解决
  • 综合应用WPF/WCF/WF/LINQ之三十:代码生成器之DBMLToDAL
  • Cocos Creator 音频API控制调频
  • OpenGL ES 之对各种坐标系统的记录理解
  • Git 仓库结构 (二)***
  • 使用WCF Test Client(WcfTestClient.exe) 来测试WCF
  • JavaScript 如何正确处理 Unicode 编码问题!
  • 【mysql】环境安装、服务启动、密码设置
  • Babel配置的不完全指南
  • Docker 1.12实践:Docker Service、Stack与分布式应用捆绑包
  • java 多线程基础, 我觉得还是有必要看看的
  • js面向对象
  • PHP变量
  • Quartz实现数据同步 | 从0开始构建SpringCloud微服务(3)
  • ReactNative开发常用的三方模块
  • Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
  • 高度不固定时垂直居中
  • 小程序 setData 学问多
  • 阿里云重庆大学大数据训练营落地分享
  • 国内开源镜像站点
  • ​DB-Engines 12月数据库排名: PostgreSQL有望获得「2020年度数据库」荣誉?
  • #pragma once
  • #每天一道面试题# 什么是MySQL的回表查询
  • #我与Java虚拟机的故事#连载01:人在JVM,身不由己
  • (06)Hive——正则表达式
  • (2)Java 简介
  • (4)事件处理——(7)简单事件(Simple events)
  • (4.10~4.16)
  • (MATLAB)第五章-矩阵运算
  • (Pytorch框架)神经网络输出维度调试,做出我们自己的网络来!!(详细教程~)
  • (附源码)计算机毕业设计SSM教师教学质量评价系统
  • (附源码)小程序儿童艺术培训机构教育管理小程序 毕业设计 201740
  • (规划)24届春招和25届暑假实习路线准备规划
  • (黑马出品_高级篇_01)SpringCloud+RabbitMQ+Docker+Redis+搜索+分布式
  • (三)Honghu Cloud云架构一定时调度平台
  • (数位dp) 算法竞赛入门到进阶 书本题集
  • .NET 5种线程安全集合
  • .NET Compact Framework 多线程环境下的UI异步刷新
  • .net6使用Sejil可视化日志
  • .NetCore部署微服务(二)
  • @31省区市高考时间表来了,祝考试成功
  • @JsonFormat与@DateTimeFormat注解的使用
  • [ JavaScript ] JSON方法
  • [ MSF使用实例 ] 利用永恒之蓝(MS17-010)漏洞导致windows靶机蓝屏并获取靶机权限
  • [20140403]查询是否产生日志
  • [IOI2007 D1T1]Miners 矿工配餐