博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FOSCommentBundle功能包:设置Doctrine ORM映射
阅读量:7013 次
发布时间:2019-06-28

本文共 2069 字,大约阅读时间需要 6 分钟。

Step 2a: Setup Doctrine ORM mapping

The ORM implementation does not provide a concrete Comment 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.

ORM实现并不提供为您所用的具体评论类,您必须要创建一个。您可以通过功能包提供扩展抽象实体类并创建适当的映射。

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

还有线索类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
// src/MyProject/MyBundle/Entity/Thread.php
namespace 
MyProject\MyBundle\Entity;
use 
Doctrine\ORM\Mapping 
as 
ORM;
use 
FOS\CommentBundle\Entity\Thread 
as 
BaseThread;
/**
 
* @ORM\Entity
 
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 
*/
class 
Thread 
extends 
BaseThread
{
    
/**
     
* @var string $id
     
*
     
* @ORM\Id
     
* @ORM\Column(type="string")
     
*/
    
protected 
$id
;
}

Configure your application(配置您的应用程序)

1
2
3
4
5
6
7
8
9
# app/config/config.yml
fos_comment:
    
db_driver: orm
    
class
:
        
model:
            
comment: MyProject\MyBundle\Entity\Comment
            
thread: MyProject\MyBundle\Entity\Thread
assetic:
    
bundles: [ 
"FOSCommentBundle" 
]

Or if you prefer XML:

或者您喜爱XML:

1
2
3
4
5
6
7
8
9
10
11
12
# app/config/config.xml
<
fos_comment:config 
db-driver
=
"orm"
>
    
<
fos_comment:class
>
        
<
fos_comment:model
            
comment
=
"MyProject\MyBundle\Entity\Comment"
            
thread
=
"MyProject\MyBundle\Entity\Thread"
        
/>
    
</
fos_comment:class
>
</
fos_comment:config
>
<
assetic:config
>
    
<
assetic:bundle 
name
=
"FOSCommentBundle" 
/>
</
assetic:config
>

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

.

本文转自 firehare 51CTO博客,原文链接:http://blog.51cto.com/firehare/1256895,如需转载请自行联系原作者
你可能感兴趣的文章
前端状态管理与有限状态机
查看>>
读Zepto源码之Data模块
查看>>
Redux助力美团点评前端进阶之路
查看>>
【闭包概念】关于闭包概念不同解读——你可以自己理解。
查看>>
More-iOS国际化一站式解决方案
查看>>
BCH一周年:从硬分叉到顺风顺水
查看>>
数据结构和算法面试题系列—排序算法之快速排序
查看>>
打破行业壁垒!阿里云OpenSearch开启个性化搜索里程碑
查看>>
面试官,你再问我 Bit Operation 试试?
查看>>
PSV 3.60 固化升级到 3.68 破解完全攻略
查看>>
Android 路由框架
查看>>
vue踩坑记- Cannot find module 'wrappy'
查看>>
【实操干货】KVM命令管理虚拟机与性能优化
查看>>
机器学习资料合计(一)
查看>>
webpack由浅入深——(webapck简易版)
查看>>
2 - 建立 Django 博客应用
查看>>
【iOS报错】“this class is not key value coding-compliant for the key userPhoneNum”给字典设置键值对的时候报错...
查看>>
UI技术总结--性能优化
查看>>
Android NDK JNI 开发之旅01 环境搭建入门篇
查看>>
Javascript之迭代器模式
查看>>