SHOW:
|
|
- or go back to the newest paste.
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 | - | if ($form->isSubmitted() && $form->isValid()) { |
15 | + | |
16 | - | $em = $this->getDoctrine()->getManager(); |
16 | + | |
17 | ||
18 | - | $em->flush(); |
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 | } |