/** * Creates a new PostComment entity. * * @Route("/(post_id)", name="postcomment_create") * @Method("POST") * @Template("ApplicationBundle:PostComment:new.html.twig") */ public function createAction(Request $request) { $entity = new PostComment(); $postId = $request->get('post_id'); $post = $this->getDoctrine()->getRepository('ApplicationBundle:Post')->find($postId); $entity->setPost($post); $form = $this->createCreateForm($entity); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); } return $this->redirect($this->generateUrl('post_show', array('id' => $entity->getPost()->getId()))); }
/** * Finds and displays a Post entity. * * @Route("/{id}", name="post_show") * @Method("GET") * @Template() */ public function showAction($id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('ApplicationBundle:Post')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Post entity.'); } $deleteForm = $this->createDeleteForm($id); $comment = new PostComment(); $comment->setPost($entity); $form = $this->createForm(new PostCommentType(), $comment, array('action' => $this->generateUrl('postcomment_create', array('post_id' => $entity->getId())), 'method' => 'POST')); $form->add('submit', 'submit', array('label' => 'Create')); $entities = $em->getRepository('ApplicationBundle:PostComment')->findBy(array('post' => $entity)); return array('entity' => $entity, 'delete_form' => $deleteForm->createView(), 'comment_form' => $form->createView(), 'comments' => $entities); }