public function editAction($userId) { $request = $this->get('request'); $service = $this->get('users.users_list_service'); try { $userDetails = $service->getUserDetails($userId); } catch (\Exception $ex) { throw $ex; } $user = new User(); $user->setFirstName($userDetails['first_name']); $user->setLastName($userDetails['last_name']); $form = $this->createFormBuilder($user)->add('first_name', 'text')->add('last_name', 'text')->add('save', 'submit', array('label' => 'Update'))->getForm(); if ($request->getMethod() == 'POST') { $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $user = new User(); $user->setId($userId); $user->setFirstName($form["first_name"]->getData()); $user->setLastName($form["last_name"]->getData()); $service->updateUser($user); return $this->redirectToRoute('users_homepage'); } } return $this->render('UsersBundle:Users:edit.html.twig', array('form' => $form->createView())); }
public function updateUser(User $user) { $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder->update('users', 'u')->set('u.first_name', ':first_name')->set('u.last_name', ':last_name')->where('u.id = :id')->setParameter('first_name', $user->getFirstName())->setParameter('last_name', $user->getLastName())->setParameter('id', $user->getId()); return $queryBuilder->execute(); }