ajouter altorouter

correction_routeur
gwplanchon 1 year ago
parent 92a28b68ae
commit e394aab4a2

@ -0,0 +1,3 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

@ -4,11 +4,8 @@ use Exception;
//gerer la connexion des admins //gerer la connexion des admins
class AdminController { class AdminController {
public function __construct(){ public function __construct(string $action){
//TODO actions, liste actions, actions autorisées
global $twig; global $twig;
//on démarre ou reprend la session, obtenir $_SESSION
session_start();
//on initialise un tableau d'erreur pour etre utilisé par la vue erreur //on initialise un tableau d'erreur pour etre utilisé par la vue erreur
$dVueEreur = []; $dVueEreur = [];
@ -17,17 +14,18 @@ class AdminController {
if($_SESSION["isAdmin"]==true){ if($_SESSION["isAdmin"]==true){
//donner la page admin a l'admin //donner la page admin a l'admin
try { try {
$action = $_REQUEST['admin'] ?? null;
switch($action) { switch($action) {
case null: case '':
echo $twig->render('admin/accueil.html'); echo "accueil admin";exit;
// echo $twig->render('admin/accueil.html');
break; break;
case 'stats': case 'stats':
echo $twig->render('admin/stats.html'); echo "stats admin";exit;
// echo $twig->render('admin/stats.html');
break; break;
case 'ajouterScientifiques': case 'ajouterScientifiques':
echo $twig->render('admin/ajouter.html'); echo "page ajout scientifiques admin";exit;
// echo $twig->render('admin/ajouter.html');
break; break;
//mauvaise action //mauvaise action
default: default:

@ -9,9 +9,18 @@ class FrontController
{ {
public function __construct() public function __construct()
{ {
global $twig; global $twig, $router;
//$con = new Connection("mysql:host=mysql;dbname=iut", "aljeudilem", "22061337");
$router->map('GET|POST', '/', 'null');
$router->map('GET|POST', '/join', 'join');
$router->map('GET|POST', '/create', 'create');
$router->map('GET|POST', '/login', 'login');
$router->map('GET|POST', '/admin/[a:action]?', 'admin');
$router->map('GET|POST', '/validationFormulaire', 'validationFormulaire');
$router->map('GET|POST', '/logout', 'disconnect');
$con = new Connection("mysql:host=mysql;dbname=iut", "aljeudilem", "22061337");
// Tableau qui contient les messages d'erreur // Tableau qui contient les messages d'erreur
$dVueErreur = []; $dVueErreur = [];
@ -23,10 +32,17 @@ class FrontController
$dVue['pseudo'] = $_SESSION['pseudo']; $dVue['pseudo'] = $_SESSION['pseudo'];
try { try {
$action = $_REQUEST['action'] ?? null; $match = $router->match();
if (!$match) {
throw new \Exception('Wrong call');
}
$action=$match['params']['action'] ?? "";
//$id=$match['params']['id'] ?? null;
switch($action) { switch($match['target']) {
case null: case 'null':
echo $twig->render('accueil.html', ['dVue' => $dVue]); echo $twig->render('accueil.html', ['dVue' => $dVue]);
break; break;
case 'join': case 'join':
@ -39,7 +55,7 @@ class FrontController
$this->ValidationFormulaire($dVueErreur, $dVue); $this->ValidationFormulaire($dVueErreur, $dVue);
break; break;
case 'admin': case 'admin':
new AdminController(); new AdminController($action);
break; break;
case 'login': case 'login':
if(empty($_SESSION) && !isset($_REQUEST['login'])) if(empty($_SESSION) && !isset($_REQUEST['login']))
@ -76,7 +92,7 @@ class FrontController
echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]);
echo $twig->render('login.html'); echo $twig->render('login.html');
} catch (\Exception $e2) { } catch (\Exception $e2) {
$dVueErreur[] = 'Erreur inattendue !'; $dVueErreur[] = 'Erreur inattendue !'.$e2->getMessage();
echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]);
} }

@ -11,8 +11,15 @@
'cache' => false, 'cache' => false,
]); ]);
//altorouter
$router = new AltoRouter();
$router->setBasePath('/public_html/ScienceQuest');
$cont = new FrontController(); $cont = new FrontController();
/* /*
try{ try{

Loading…
Cancel
Save