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