doupingmao1903 2016-02-01 11:41
浏览 12

FOSCommentBundle和thread_id

I've followed FOSComment's instruction to have multiple threads in one page. It's ok everything works. Just kidding, the world isn't that beautiful.

I'll try to explain my problem : When I submit my comment, i've got Integrity constraint violation due to the URL, I don't pass any Thread_id in my URL.

I found the piece of code in my controller which does that, but I've got no idea how to correct it. So, there's my controller :

public function indexAction(Request $request)
{
    $stmt = $this->getDoctrine()->getEntityManager()
        ->getConnection()
        ->prepare('select ttrss_entries.id, title, content, body, thread_id '
                . 'FROM ttrss_entries '
                . 'LEFT JOIN ttrss_tags ON ttrss_entries.id = ttrss_tags.post_int_id '
                . 'LEFT JOIN comment on comment.thread_id = ttrss_entries.id '
                . 'WHERE ttrss_tags.tag_name = "politique" '
                . 'GROUP BY ttrss_entries.id');
    $stmt->execute();
    $result = $stmt->fetchAll();

    //Here my problem
    $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());

    $this->container->get('fos_comment.manager.thread')->saveThread($thread);
    }

    $comments = $this->container->get('fos_comment.manager.comment')->findCommentTreeByThread($thread);

    return $this->render('AppBundle:Politique:index.html.twig', array(
        'comments' => $comments,
        'thread' => $thread,
        'entities' => $result,
         ));


}

Here my view :

<div class="fos_comment_thread" data-thread-id="{{ thread.id }}">
 {% include 'FOSCommentBundle:Thread:comments.html.twig' with {
        'comments': comments,
        'thread': thread
 } %}

Thanks in advance for your help

PS : I'm a newbie with Symfony.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题