FOSCommentBundle和thread_id

时间:2016-02-01 11:41:53

标签: php symfony twig multiple-views foscommentbundle

我跟着FOSComment's instruction在一个页面中有多个线程。一切正常都行。开个玩笑,世界并不美丽。

我会尝试解释一下我的问题:当我提交评论时,由于网址导致我违反了诚信约束,我不会在我的网址中传递任何Thread_id。

我在控制器中找到了那段代码,但我还不知道如何纠正。所以,我的控制器是:

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,
         ));


}

我的观点在这里:

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

提前感谢您的帮助

PS:我是Symfony的新手。

0 个答案:

没有答案