diff --git a/app/controller/JeuController.php b/app/controller/JeuController.php index 220d7a0e8f062c6638dec3fe2388bbe17a410ee0..275b339d27dccc939d78f2a5227724f1feb8c4c9 100644 --- a/app/controller/JeuController.php +++ b/app/controller/JeuController.php @@ -3,8 +3,13 @@ class JeuController extends Controller { public function display() { $slug = $this->route["params"]["slug"]; //cf. le commentaire dans ProfilController.php - $this->view->jeu = Jeu::getFromSlug($slug); - $this->view->display(); + if(in_array($slug, Jeu::getSlugList())) { // si le nom du jeu cherché est dans notre BDD, on peut l'afficher + $this->view->jeu = Jeu::getFromSlug($slug); + $this->view->display(); + } + else { + header('Location:'.BASE_URL.'/404'); + } } public function displayListe() { diff --git a/app/model/Jeu.php b/app/model/Jeu.php index 4590ba4e82e3104ffa92bfe925f98e7f40eb7825..d16773f3b8c40bec891c9e4f771e6a3b1aca9887 100644 --- a/app/model/Jeu.php +++ b/app/model/Jeu.php @@ -21,6 +21,17 @@ class Jeu extends Model { } + public static function getSlugList() { + $db = Database::getInstance(); + $sql = "SELECT slug FROM R_jeu"; + $stmt = $db->query($sql); + $return = array(); + while($elt = $stmt->fetch()) { + array_push($return, $elt['slug']); + } + return $return; + } + public static function checkExists($slug_jeu) { // méthode permettant de vérifier si un jeu existe dans la BDD $db = Database::getInstance(); // on récupère la connexion à la BDD $sql = "SELECT * FROM R_jeu WHERE slug = :slug";