voilà mon problème.
Quand je lance url : http://127.0.0.1:3000/show/100
j'ai ce retour : Notice: Undefined variable: resultat in /home/zapa/Documents/workspace/www/pratique-symfony-routing/pages/show.php on line 15
je ne comprends pas pourquoi ...
Si tu as une explication je suis preneur merci.
page index.php
`<?php
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
require DIR . '/vendor/autoload.php';
$routeList = new Route('/');
$routeCreate = new Route('/create');
$routeShow = new Route('/show/{id}');
$collection = new RouteCollection();
$collection->add('list', $routeList);
$collection->add('show', $routeShow);
$collection->add('create', $routeCreate);
$matcher = new UrlMatcher($collection, new RequestContext());
Bonjour Lior,
voilà mon problème. Quand je lance url : http://127.0.0.1:3000/show/100 j'ai ce retour : Notice: Undefined variable: resultat in /home/zapa/Documents/workspace/www/pratique-symfony-routing/pages/show.php on line 15
je ne comprends pas pourquoi ... Si tu as une explication je suis preneur merci.
page index.php
`<?php
use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection;
require DIR . '/vendor/autoload.php';
$routeList = new Route('/'); $routeCreate = new Route('/create'); $routeShow = new Route('/show/{id}');
$collection = new RouteCollection(); $collection->add('list', $routeList); $collection->add('show', $routeShow); $collection->add('create', $routeCreate);
$matcher = new UrlMatcher($collection, new RequestContext());
$pathInfo = $_SERVER['PATH_INFO'] ?? '/';
try { $resulat = $matcher->match($pathInfo);
} catch (ResourceNotFoundException $e) { require 'pages/404.php'; return;
}`
page show.php
`<?php
$data = require_once "data.php"; $id = $resultat['id'];
if (!$id || !array_key_exists($id, $data)) { throw new Exception("La tâche demandée n'existe pas !"); }
// Si tout va bien, on récupère la tâche correspondante et on affiche $task = $data[$id];`