diff --git a/GamePedia/index.php b/GamePedia/index.php index 63bd77caa17e8d619e109d6272e886a6f0ec4a09..62540f37168a05dce0693ec2bd3045e911d7951e 100644 --- a/GamePedia/index.php +++ b/GamePedia/index.php @@ -26,12 +26,12 @@ $app->get('/',function () use ($app) { $app->get('/api/games/:id',function ($id) { $c = new ControleurGame(); $c->getGame($id); -}); +})->name('getGame'); // Affiche tous les jeu paginé au format JSON $app->get('/api/games/',function () { $c = new ControleurGame(); $c->getGames(); -})->name('getGame'); +})->name('getGames'); // Affiche les commentaires d'un jeu $app->get('/api/games/:id/comments',function ($id) { $c = new ControleurGame(); diff --git a/GamePedia/src/controleurs/ControleurGame.php b/GamePedia/src/controleurs/ControleurGame.php index e4080f1f79df668946d89104b4e3e45125e523e2..e5e3598daad2d8c25e229ba37f1e99636ca8bbd1 100644 --- a/GamePedia/src/controleurs/ControleurGame.php +++ b/GamePedia/src/controleurs/ControleurGame.php @@ -9,8 +9,14 @@ use Slim\Slim; class ControleurGame { public function getGame($id){ + $route = Slim::getInstance()->request->getResourceUri(); $game = Game::where('id', '=', $id)->first(); - $v = new VueGame(json_encode($game)); + $results['game'] = $game; + $results['links'] = [ + "comments" =>["href" => $route."/comments"] , + "characters" =>["href" => $route."/characters"] + ]; + $v = new VueGame(json_encode($results)); $v->render('getGame'); } @@ -20,7 +26,7 @@ class ControleurGame $response = Game::paginate(200, ['*'], 'page', $page); $json = (json_decode(json_encode($response),true)); foreach ($json['data'] as $game) { - $route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia',Slim::getInstance()->urlFor('getGame')); + $route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia',Slim::getInstance()->urlFor('getGames')); $url = $route[1]."{$game['id']}"; $results['games'][] = ["game" => $game, "links" => ["self" => ["href" => $url]]]; }