sanjiisan

Untitled

Sep 13th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1.  
  2. /**
  3. * @Route("/createBook/", name="createBook")
  4. */
  5. public function createBookAction(Request $request)
  6. {
  7. $title = $request->request->get('title');
  8. $description = $request->request->get('description');
  9. $rating = $request->request->get('rating');
  10. $authorId = $request->request->get('author');
  11.  
  12. $em = $this->getDoctrine()->getEntityManager();
  13. $authorRepo = $em->getRepository('CoderslabBundle:Author');
  14.  
  15. $author = $authorRepo->find($authorId);
  16.  
  17. $newBook = new Book();
  18. $newBook->setTitle($title);
  19. $newBook->setDescription($description);
  20. $newBook->setRating($rating);
  21.  
  22. $newBook->setAuthor($author);
  23.  
  24. $em->persist($author);
  25. $em->persist($newBook);
  26. $em->flush();
  27.  
  28.  
  29. return $this->redirect($this->generateUrl('showBook', ['id' => $newBook->getId()]));
  30. }
Add Comment
Please, Sign In to add comment