Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. /**
  2. * Creates a new Comment entity.
  3. *
  4. * @Route("/{torrent_id}/create", name="comment_create")
  5. * @Method("post")
  6. * @Secure(roles="ROLE_USER")
  7. */
  8. public function createAction($torrent_id) {
  9. $entity = new Comment();
  10. $form = $this->createForm(new CommentFormType(), $entity);
  11. $request = $this->getRequest();
  12.  
  13. $form->bindRequest($request);
  14. if ($form->isValid()) {
  15. $em = $this->getDoctrine()->getEntityManager();
  16. $user = $this->container->get('security.context')->getToken()->getUser();
  17. $torrent = $em->getRepository('RootyTorrentBundle:Torrent')->findOneById($torrent_id);
  18.  
  19. $entity->setTorrent($torrent);
  20. $entity->setAddedBy($user);
  21. $entity->setDateAdded(new \DateTime('now'));
  22.  
  23. $em->persist($entity);
  24. $em->flush();
  25.  
  26. return $this->redirect($this->generateUrl('torrent_show', array('id' => $torrent_id)).'#'.$entity->getId());
  27. }
  28. return new Response('An error occured with form sumbission');
  29. }
Add Comment
Please, Sign In to add comment