public function insertAction(Request $request)
 {
     //$movie = new Movie($request->get('title'), str_replace('.', '', $request->get('price')), $request->get('description'));
     $movie = new Movie();
     if ($request->get('title') != null) {
         $movie->setTitle($request->get('title'));
     }
     if (str_replace('.', '', $request->get('price')) != null) {
         $movie->setPrice(str_replace('.', '', $request->get('price')));
     }
     if ($request->get('description') != null) {
         $movie->setDescription($request->get('description'));
     }
     $validator = $this->get('validator');
     $errors = $validator->validate($movie);
     if (count($errors) > 0) {
         $errorsString = (string) $errors;
         return $this->render('movies/customErrorPage.html.twig', array('errorsString' => $errorsString));
     }
     /* em stands for entity manager */
     $em = $this->getDoctrine()->getManager();
     $em->persist($movie);
     $em->flush();
     return $this->redirectToRoute('movies');
 }
Exemplo n.º 2
0
 public function relatedEntitiesAction()
 {
     $category = new Entry();
     $category->setName('Main Products');
     $product = new Movie();
     $product->setName('Foo');
     $product->setPrice(19.99);
     $product->setDescription('Lorem ipsum dolor');
     // relate this product to the category
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Created product id: ' . $product->getId() . ' and category id: ' . $category->getId());
     //fetchin related
     $product = $this->getDoctrine()->getRepository('AppBundle:Product')->find($id);
     $categoryName = $product->getCategory()->getName();
 }