Selecteur du controlleur depuis l'URL[1] réalisé. Si non ok, alors affichage de toutes les possiblitées.

This commit is contained in:
Cédric Abonnel 2022-12-29 23:25:42 +01:00
parent 7b996cc5f6
commit 4caafe16d5
1 changed files with 20 additions and 4 deletions
public

View File

@ -1,4 +1,8 @@
<?php
require "../bootstrap.php";
use Src\Controller\CompteurController;
@ -18,10 +22,13 @@ $endpoints = array(
'compteur',
'releve'
);
/*
if ( ! in_array($uri[1], $endpoints) ) {
header("HTTP/1.1 404 Not Found");
exit();
}
*/
// the user id is, of course, optional and must be a number:
$id = null;
@ -31,9 +38,18 @@ if (isset($uri[2])) {
$requestMethod = $_SERVER["REQUEST_METHOD"];
// pass the request method and user ID to the CompteurController and process the HTTP request:
$qsd = CompteurController
$controller = new $qsd($dbConnection, $requestMethod, $id);
$controller->processRequest();
switch($uri[1]) {
case 'compteur':
$controller = new CompteurController($dbConnection, $requestMethod, $id);
$controller->processRequest();
break;
case 'releve':
break;
default:
echo json_encode($endpoints);
break;
}