<?php /** * Obtiene todas las peliculas de la base de datos */ /** * Constantes para construcción de respuesta */ const ESTADO = "estado"; const DATOS = "peliculas"; const MENSAJE = "mensaje"; const CODIGO_EXITO = 1; const CODIGO_FALLO = 2; require '../data/peliculas.php'; if ($_SERVER['REQUEST_METHOD'] == 'GET') { // Obtener peliculas de la base de datos $peliculas = Peliculas::getAll(); // Definir tipo de la respuesta header('Content-Type: application/json'); if ($peliculas) { $datos[ESTADO] = CODIGO_EXITO; $datos[DATOS] = $peliculas; print json_encode($datos); } else { print json_encode(array(ESTADO => CODIGO_FALLO, MENSAJE => "Ha ocurrido un error")); } }