Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /**
  2.      * @Rest\Post("/answer")
  3.      */
  4.     public function postAnswerAction(Request $request)
  5.     {
  6.         $answer = new Answer();
  7.  
  8.         $data = $request->request->all();
  9.         $em = $this->getDoctrine()->getManager();
  10.         foreach ($data as $item) {
  11.  
  12.             $form = $this->createForm(AnswerType::class, $answer);
  13.             $form->submit($item);
  14.             if ($form->isSubmitted() && $form->isValid()) {    
  15.                 $em->persist($answer);
  16.             }
  17.  
  18.         }
  19.         $em->flush();
  20.         return $this->handleView(
  21.             $form->getErrors(true)->count() > 0
  22.                 ? $this->view($form->getErrors(true))
  23.                 : $this->view(['status' => 'created']
  24.                 , Response::HTTP_CREATED, ['Access-Control-Allow-Origin' => '*'])
  25.         );
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement