public function showAction($id, Request $request) { $post = $this->getDoctrine()->getRepository('BlogBundle:Post')->find($id); if (!$post) { throw $this->createNotFoundException('Brak postu o id ' . $id); } $comment = new Comment(); $comment->setPost($post); $comment->setDate(new \DateTime('now')); $form = $this->createFormBuilder($comment)->add('author', TextType::class, array('label' => 'Imię'))->add('content', TextareaType::class, array('label' => 'Treść'))->add('save', SubmitType::class, array('label' => 'Dodaj komentarz'))->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($comment); $em->flush(); $this->addFlash('notice', 'Twój komentarz został dodany!'); return $this->redirectToRoute('blog_showpost', array('id' => $id)); } else { return $this->render('BlogBundle:Default:showpost.html.twig', array('post' => $post, 'form' => $form->createView())); } }