/**
  * Creates a new Comment entity.
  *
  * @Route("/create/post/{id}", name="monster_test_comment_create", requirements={"id"="\d+"})
  * @Method("POST")
  */
 public function createAction(Request $request, Post $issue)
 {
     if (!$request->isXmlHttpRequest()) {
         return new JsonResponse(array('message' => 'You can access this only using Ajax!'), 400);
     }
     // unset($request->request['magecore_bundle_testtaskbundle_comment']['body']);
     $entity = new Comment();
     $entity->setPost($issue);
     //$entity->setAuthor($this->getUser());
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         //$issue->addCollaborator($this->getUser());
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         $em->flush();
         return $this->listAction($issue);
     }
     $responce = new JsonResponse(array('message' => 'Error', 'form' => $this->renderView('MonstertestBundle:Comment:form.html.twig', array('entity' => $entity, 'form' => $form->createView()))), 400);
     return $responce;
 }
Esempio n. 2
0
 /**
  * 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('MonstertestBundle:Post')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Post entity.');
     }
     $comment = new Comment();
     $comment->setPost($entity);
     $addCommentForm = $this->createForm(new CommentType(), $comment, array('action' => $this->generateUrl('monster_test_comment_create', array('id' => $entity->getId()))));
     $deleteForm = $this->createDeleteForm($id);
     return array('entity' => $entity, 'delete_form' => $deleteForm->createView(), 'addComment' => $addCommentForm->createView());
 }