FOSCommentBundle and thread_id

325 Views Asked by At

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

There are 0 best solutions below