public function editar($id = 0) { if (!$_POST) { $pregunta = PreguntasModel::getId($id); if ($pregunta) { echo $this->view->render('preguntas/formulariopregunta', array('datos' => get_object_vars($pregunta), 'accion' => 'editar')); } else { header("location: /preguntas/todas"); } } else { $datos = array('asunto' => isset($_POST["asunto"]) ? $_POST["asunto"] : "", 'cuerpo' => isset($_POST["cuerpo"]) ? $_POST["cuerpo"] : "", 'id_pregunta' => isset($_POST["id_pregunta"]) ? $_POST["id_pregunta"] : ""); if (PreguntasModel::edit($datos)) { header('location: /preguntas/todas'); } else { echo $this->view->render('preguntas/formulariopregunta', array('errores' => array('Error al editar'), 'datos' => $_POST, 'accion' => 'editar')); } } }