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 字段,用来保存被解析后的评论。

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.


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


# app/config/config.yml
        markup: your_markup_service

That is it!

Return to the index.