FOSCommentBundle功能包:安装解析器以便标识评论

本文介绍如何使用FOSComment功能包实现自定义的评论解析,包括配置RawCommentInterface、设置rawBody字段以及安装自定义标识解析器等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Step 9: Using a markup parser

FOSComment bundle allows a developer to implement RawCommentInterface, which will tell the bundle that your comments are to be parsed for a markup language.

FOSComment功能包允许开发者实现 RawCommentInterface接口,该接口告诉功能包您的评论将作为标识语言解析。


You will also need to configure a rawBody field in your database to store the parsed comments.

您也需要在您的数据库中配置 rawBody 字段,用来保存被解析后的评论。

1
2
3
4
5
6
7
8
use  FOS\CommentBundle\Model\RawCommentInterface;
class  Comment  extends  BaseComment  implements  RawCommentInterface
     /**
      * @ORM\Column(name="rawBody", type="text", nullable=true)
      * @var string
      */
     protected  $rawBody ;
     ... also add getter  and  setter  as  defined in the RawCommentInterface ...


When a comment is added, it is parsed and setRawBody() is called with the raw version of the comment which is then stored in the database and shown when the comment is later rendered.

当添加一个评论时,它被解析,然后调用 setRawBody()方法,并且与原始版本的评论一起保存在数据库中,然后在该评论被渲染时显示。


Any markup language is supported, all you need is a bridging class that implements Markup\ParserInterface and returns the parsed result of a comment in raw html to be displayed on the page.

支持任何标识语言,您所需要做的就是一个桥接类,实现Markup\ParserInterface,然后返回解析结果,并在页面上显示该评论的原始HTML。


To set up your own custom markup parser, you are required to define a service that implements the above interface, and to tell FOSCommentBundle about it,adjust the configuration accordingly

要安装您自己定制的标识解析器,您需要定义一个实现了上述接口的服务,并告诉FOSCommentBundle功能包相应地调整配置。

1
2
3
4
# app/config/config.yml
fos_comment:
     service:
         markup: your_markup_service


That is it!

Return to the index.

返回到指南索引页


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值