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,如需转载请自行联系原作者

相关文章
|
数据库
一对多关系domain Model中设置使用AutoMapper时出错
一对多关系domain Model中设置使用AutoMapper时出错
143 0
一对多关系domain Model中设置使用AutoMapper时出错
|
JSON API 数据格式
FastAPI(13)- 详解 Fields,针对 Pydantic Model 内部字段添加额外校验和元数据
FastAPI(13)- 详解 Fields,针对 Pydantic Model 内部字段添加额外校验和元数据
432 0
FastAPI(13)- 详解 Fields,针对 Pydantic Model 内部字段添加额外校验和元数据
|
存储 安全 Android开发
【Android 安装包优化】资源混淆 ( resources.arsc 资源映射表文件格式 | 头文件 数据格式 | 全局字符串池 数据格式 | 包数据 数据格式 | 包头 数据格式 )(二)
【Android 安装包优化】资源混淆 ( resources.arsc 资源映射表文件格式 | 头文件 数据格式 | 全局字符串池 数据格式 | 包数据 数据格式 | 包头 数据格式 )(二)
242 0
【Android 安装包优化】资源混淆 ( resources.arsc 资源映射表文件格式 | 头文件 数据格式 | 全局字符串池 数据格式 | 包数据 数据格式 | 包头 数据格式 )(二)
|
存储 Android开发 数据格式
【Android 安装包优化】资源混淆 ( resources.arsc 资源映射表文件格式 | 头文件 数据格式 | 全局字符串池 数据格式 | 包数据 数据格式 | 包头 数据格式 )(一)
【Android 安装包优化】资源混淆 ( resources.arsc 资源映射表文件格式 | 头文件 数据格式 | 全局字符串池 数据格式 | 包数据 数据格式 | 包头 数据格式 )(一)
183 0
【Android 安装包优化】资源混淆 ( resources.arsc 资源映射表文件格式 | 头文件 数据格式 | 全局字符串池 数据格式 | 包数据 数据格式 | 包头 数据格式 )(一)
user.config.ts文件里定义的配置是如何合并到SAP Spartacus的标准配置里去的
user.config.ts文件里定义的配置是如何合并到SAP Spartacus的标准配置里去的
214 0
user.config.ts文件里定义的配置是如何合并到SAP Spartacus的标准配置里去的
HANA report里默认filter的工作机制
HANA report里默认filter的工作机制
83 0
HANA report里默认filter的工作机制
|
Web App开发
ORM映射框架总结--文件下载
本段代码提供了asp.net 中的各种文件下载方式。   代码   1 /**  2  * 日期:2009-3-13  3  * 作者:  4  * 功能:下载文件  5  * */  6   7 using System;  8 using System.
598 0
|
存储 缓存 数据库
ORM映射框架总结--实体分析器
1.       什么是数据分析器 前面一篇文章讲到过数据分析器,什么是数据分析器。其实很容易理解,就是对数据进行分析采集的一个工具,说白了就是一个小程序,在本ORM框架中对实体对象进行必要的数据分析,获得实体对象的各种信息缓存,以便在后续的工作中直接提取数据。
742 0

热门文章

最新文章