Guest User

Untitled

a guest
Feb 22nd, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. public function insertAction(Request $request)
  2. {
  3.     $movie = new Movie();
  4.  
  5.     if($request->get('title') != null)
  6.     {
  7.         $movie->setTitle($request->get('title'));
  8.     }
  9.    
  10.     if(str_replace('.', '', $request->get('price')) != null)
  11.     {
  12.         $movie->setPrice(str_replace('.', '', $request->get('price')));
  13.     }
  14.    
  15.     if($request->get('description') != null)
  16.     {
  17.         $movie->setDescription($request->get('description'));
  18.     }
  19.  
  20.     $validator = $this->get('validator');
  21.     $errors = $validator->validate($movie);
  22.  
  23.     if (count($errors) > 0)
  24.     {
  25.         $errorsString = (string) $errors;
  26.         return new Response('(Click <a href="{{ path('movies') }}">here</a> to go back) Something was missing, please try adding entry again: ' . $errorsString);
  27.     }
  28.    
  29.     $em = $this->getDoctrine()->getManager();
  30.     $em->persist($movie);
  31.     $em->flush();
  32.  
  33.     return $this->redirectToRoute('movies');
  34. }
Add Comment
Please, Sign In to add comment