我按照FOSComment 的说明在一页中有多个线程。没关系,一切正常。开个玩笑,世界没有那么美好。
我将尝试解释我的问题:当我提交评论时,由于 URL,我违反了完整性约束,我没有在我的 URL 中传递任何 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 的新手。