예제 #1
0
 public function modificarContacto(Application $app, Request $request, $id)
 {
     $contactoModel = new ContactoModel($app);
     $contacto = $contactoModel->retrieveById($id);
     $nombre = $request->request->get("nombre") != null ? $request->request->get("nombre") : $contacto["nombre"];
     $apellido = $request->request->get("apellido") != null ? $request->request->get("apellido") : $contacto["apellido"];
     $direccion = $request->request->get("direccion") != null ? $request->request->get("direccion") : $contacto["direccion"];
     $contactoModel->update($id, $nombre, $apellido, $direccion);
     $contacto = $contactoModel->retrieveById($id);
     return $app->json(array("message" => "success", "contacto" => $contacto));
 }
예제 #2
0
 public function modificar(Application $app, Request $request, $id)
 {
     $contactoModel = new ContactoModel($app);
     $contactoData = $contactoModel->retrieveById($id);
     $contacto = new Contacto();
     $contacto->setNombre($contactoData['nombre']);
     $contacto->setApellido($contactoData['apellido']);
     $contacto->setDireccion($contactoData['direccion']);
     $form = $app["form.factory"]->createBuilder("form", $contacto, array("action" => "/modificar/{$id}"))->add("nombre")->add("apellido")->add("direccion")->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $formValues = $request->request->get("form");
         $contactoModel->update($id, $formValues['nombre'], $formValues['apellido'], $formValues['direccion']);
         $app->redirect("/", 303);
         $subRequest = Request::create("/", "GET");
         return $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     }
     return $app['twig']->render("form.twig", array("form" => $form->createView()));
 }