From 7d783fa338d9d597d71dcb9da86af14a27b17d01 Mon Sep 17 00:00:00 2001 From: SASSU Thomas <thomas.sassu5@etu.univ-lorraine.fr> Date: Mon, 23 Mar 2020 18:15:06 +0100 Subject: [PATCH] Partie 4 --- GamePedia/index.php | 2 +- GamePedia/src/controleurs/ControleurGame.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/GamePedia/index.php b/GamePedia/index.php index 87338b3..441dfb7 100644 --- a/GamePedia/index.php +++ b/GamePedia/index.php @@ -30,6 +30,6 @@ $app->get('/api/games/:id',function ($id) { $app->get('/api/games/',function () { $c = new ControleurGame(); $c->getGames(); -}); +})->name('getGame'); $app->run(); \ No newline at end of file diff --git a/GamePedia/src/controleurs/ControleurGame.php b/GamePedia/src/controleurs/ControleurGame.php index a42f7ba..4ea410f 100644 --- a/GamePedia/src/controleurs/ControleurGame.php +++ b/GamePedia/src/controleurs/ControleurGame.php @@ -4,6 +4,8 @@ namespace gp\controleurs; use gp\modeles\Game; use gp\vues\VueGame; +use Slim\Slim; + class ControleurGame { public function getGame($id){ @@ -18,7 +20,9 @@ class ControleurGame $response = Game::paginate(200, ['*'], 'page', $page); $json = (json_decode(json_encode($response),true)); foreach ($json['data'] as $game) { - $results['games'][] = ["game" => $game, "links" => ["self" => ["href" => "/api/games/{$game['id']}"]]]; + $route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia',Slim::getInstance()->urlFor('getGame')); + $url = $route[1]."{$game['id']}"; + $results['games'][] = ["game" => $game, "links" => ["self" => ["href" => $url]]]; } $links = ["prev" =>["href" => "/api/games{$json['prev_page_url']}"] , "next" =>["href" => "/api/games{$json['next_page_url']}"]]; $results['links'] = $links; -- GitLab