| @@ 63-83 (lines=21) @@ | ||
| 60 | * @param Request $request | |
| 61 | * @return array|RedirectResponse | |
| 62 | */ | |
| 63 | public function userAddAction(Request $request) | |
| 64 |     { | |
| 65 | $em = $this->getDoctrine()->getManager(); | |
| 66 | $user = new User(); | |
| 67 |         $form = $this->createForm('AppBundle\Form\UserType', $user, [ | |
| 68 |             'action' => $this->generateUrl('add_user'), | |
| 69 | 'method' => 'POST', | |
| 70 |             'validation_groups' => array('registration'), | |
| 71 | ]) | |
| 72 |             ->add('Save', SubmitType::class, array( | |
| 73 | 'attr' => ['class' => 'btn pull-right btn-warning'] | |
| 74 | )); | |
| 75 | $form->handleRequest($request); | |
| 76 |         if ($form->isValid()) { | |
| 77 | $em->persist($user); | |
| 78 | $em->flush(); | |
| 79 | ||
| 80 |             return new RedirectResponse($this->generateUrl("users_list")); | |
| 81 | } | |
| 82 | return ['form' => $form->createView()]; | |
| 83 | } | |
| 84 | ||
| 85 | /** | |
| 86 |      * @Route("/user/edit/{id}", name="edit_user") | |
| @@ 93-112 (lines=20) @@ | ||
| 90 | * @param User $user | |
| 91 | * @return array|RedirectResponse | |
| 92 | */ | |
| 93 | public function userEditAction(Request $request, User $user) | |
| 94 |     { | |
| 95 | $em = $this->getDoctrine()->getManager(); | |
| 96 |         $form = $this->createForm('AppBundle\Form\UserType', $user, [ | |
| 97 |             'action' => $this->generateUrl('edit_user', array('id' => $user->getId())), | |
| 98 | 'method' => 'POST', | |
| 99 |             'validation_groups' => array('edit'), | |
| 100 | ]) | |
| 101 |             ->add('Save', SubmitType::class, array( | |
| 102 | 'attr' => ['class' => 'btn pull-right btn-warning'] | |
| 103 | )); | |
| 104 | $form->handleRequest($request); | |
| 105 |         if ($form->isValid()) { | |
| 106 | $em->persist($user); | |
| 107 | $em->flush(); | |
| 108 | ||
| 109 |             return new RedirectResponse($this->generateUrl("users_list")); | |
| 110 | } | |
| 111 | return ['form' => $form->createView()]; | |
| 112 | } | |
| 113 | } | |
| 114 | ||