Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Route("/createBook/", name="createBook")
- */
- public function createBookAction(Request $request)
- {
- $title = $request->request->get('title');
- $description = $request->request->get('description');
- $rating = $request->request->get('rating');
- $authorId = $request->request->get('author');
- $em = $this->getDoctrine()->getEntityManager();
- $authorRepo = $em->getRepository('CoderslabBundle:Author');
- $author = $authorRepo->find($authorId);
- $newBook = new Book();
- $newBook->setTitle($title);
- $newBook->setDescription($description);
- $newBook->setRating($rating);
- $newBook->setAuthor($author);
- $em->persist($author);
- $em->persist($newBook);
- $em->flush();
- return $this->redirect($this->generateUrl('showBook', ['id' => $newBook->getId()]));
- }
Add Comment
Please, Sign In to add comment