Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Creates a new Comment entity.
- *
- * @Route("/{torrent_id}/create", name="comment_create")
- * @Method("post")
- * @Secure(roles="ROLE_USER")
- */
- public function createAction($torrent_id) {
- $entity = new Comment();
- $form = $this->createForm(new CommentFormType(), $entity);
- $request = $this->getRequest();
- $form->bindRequest($request);
- if ($form->isValid()) {
- $em = $this->getDoctrine()->getEntityManager();
- $user = $this->container->get('security.context')->getToken()->getUser();
- $torrent = $em->getRepository('RootyTorrentBundle:Torrent')->findOneById($torrent_id);
- $entity->setTorrent($torrent);
- $entity->setAddedBy($user);
- $entity->setDateAdded(new \DateTime('now'));
- $em->persist($entity);
- $em->flush();
- return $this->redirect($this->generateUrl('torrent_show', array('id' => $torrent_id)).'#'.$entity->getId());
- }
- return new Response('An error occured with form sumbission');
- }
Add Comment
Please, Sign In to add comment