博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FOSCommentBundle功能包:其它添加评论到页面的方法
阅读量:6708 次
发布时间:2019-06-25

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

  • 原文出处:

  • 原文作者:

  • 授权许可:

  • 翻译人员:FireHare

  • 校对人员:

  • 适用版本:FOSCommentBundle 2.0.5

  • 文章状态:草译阶段

Step 10: Other ways of including comments in a page

The default implementation of FOSCommentBundle uses asynchronous javascriptand jQuery (optionally with easyXDM for cross domain requests) to load a comment thread into a page.

FOSCommentBundle的缺省实现是使用异步javascript和jQuery(也可以使用easyXDM进行跨域请求)来将评论线索加载到页面。

It is possible to include the thread without using javascript to load it, but needs additional work inside the controller's action.

不使用javascript来引导线索加载也是可以实现的,但需要在控制器的Action中进行额外的工作。

At a minimum, you will need to include the following in your action's PHP code:

至少,您需要在您Action中的PHP代码中包含下列语句:

public function somethingAction(Request $request){    $id = 'thread_id';    $thread = $this->container->get('fos_comment.manager.thread')->findThreadById($id);    if (null === $thread) {        $thread = $this->container->get('fos_comment.manager.thread')->createThread();        $thread->setId($id);        $thread->setPermalink($request->getUri());        // Add the thread        $this->container->get('fos_comment.manager.thread')->saveThread($thread);    }    $comments = $this->container->get('fos_comment.manager.comment')->findCommentTreeByThread($thread);    return $this->render('AcmeDemoBundle:Controller:something.html.twig', array(        'comments' => $comments,        'thread' => $thread,    ));}

Once you've included this code in your action, some code must be included in your template:

一旦您已经在您的Action中包含了上述代码,那么也必须在您的模板中包含一些代码:

{% block body %}{# ... #}
{% include 'FOSCommentBundle:Thread:comments.html.twig' with { 'comments': comments, 'thread': thread} %}
{# ... #}{% endblock body %}{% block javascript %}{# jQuery must be available in the page by this time, and make sure javascript block is after
in the DOM Tree, for example right before tag#}{% javascripts '@FOSCommentBundle/Resources/assets/js/comments.js' %}
{% endjavascripts %}{% endblock javascript %}

That is it!

转载地址:http://cgylo.baihongyu.com/

你可能感兴趣的文章
在SpringAOP中如何获取方法的参数值(实体类)以及参数名
查看>>
Charles安装和抓包
查看>>
Java数据结构与算法(五)-双向链表
查看>>
抛弃NVelocity,来玩玩Razor
查看>>
在JavaScript面向对象编程中使用继承(1)
查看>>
高铁与机场成交通信息化建设的双驾马车
查看>>
遇到问题描述:Android Please ensure that adb is correctly located at问题解决
查看>>
chmod命令
查看>>
货币的起源和职能是什么?绘制货币资金管理思维导图简单的方法介绍
查看>>
springboot+kafka+elk+docker+docker-compose+centos搭建日志收集系统
查看>>
时讯无线如何满足商业区的无线覆盖?
查看>>
2014最新open***搭建实例
查看>>
WinAPI: midiOutCachePatches - 预装音色
查看>>
finally执行顺序
查看>>
TWebBrowser 与 MSHTML(2): 获取 window 对象的时机
查看>>
【博客话题】IT人,你肿么了? ——除了IT,你还能选择什么?
查看>>
docker初步入门
查看>>
Outlook提示:无法安装或装载加载项vpmsece.dll
查看>>
使用Apache开源POI和jXLS两种API生成报表
查看>>
oracle控制台OEM无法启动
查看>>