public function insertarContacto(Application $app, Request $request) { $contactoModel = new ContactoModel($app); $nombre = $request->request->get("nombre"); $apellido = $request->request->get("apellido"); $direccion = $request->request->get("direccion"); $id = $contactoModel->register($nombre, $apellido, $direccion); return $app->json(array("message" => "success!!", "id" => $id)); }
public function registrar(Application $app, Request $request) { $contacto = new Contacto(); $form = $app["form.factory"]->createBuilder("form", $contacto)->add("nombre", "text", array("block_name" => "nombre"))->add("apellido")->add("direccion")->getForm(); $form->handleRequest($request); if ($form->isValid()) { $contactoModel = new ContactoModel($app); $formValues = $request->request->get("form"); $idContacto = $contactoModel->register($formValues['nombre'], $formValues['apellido'], $formValues['direccion']); $subRequest = Request::create("/", "GET"); return $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST); } return $app['twig']->render("form.twig", array("form" => $form->createView())); }