diff --git a/GamePedia/index.php b/GamePedia/index.php index 87338b309e2f4a07ac286a9b9626810ea7b7ac0c..441dfb7faced7bb23399978457c45f3b5127643d 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 a42f7ba962355e53d0a5a804fd15dff31b9317cf..4ea410f129076205d72042c365bc73b57efe1d2f 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;