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