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
class AdminController {
public function __construct(){
//TODO actions, liste actions, actions autorisées
public function __construct(string $action){
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
$dVueEreur = [];
@ -17,17 +14,18 @@ class AdminController {
if($_SESSION["isAdmin"]==true){
//donner la page admin a l'admin
try {
$action = $_REQUEST['admin'] ?? null;
switch($action) {
case null:
echo $twig->render('admin/accueil.html');
case '':
echo "accueil admin";exit;
// echo $twig->render('admin/accueil.html');
break;
case 'stats':
echo $twig->render('admin/stats.html');
echo "stats admin";exit;
// echo $twig->render('admin/stats.html');
break;
case 'ajouterScientifiques':
echo $twig->render('admin/ajouter.html');
echo "page ajout scientifiques admin";exit;
// echo $twig->render('admin/ajouter.html');
break;
//mauvaise action
default:

@ -9,9 +9,18 @@ class FrontController
{
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
$dVueErreur = [];
@ -23,10 +32,17 @@ class FrontController
$dVue['pseudo'] = $_SESSION['pseudo'];
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) {
case null:
switch($match['target']) {
case 'null':
echo $twig->render('accueil.html', ['dVue' => $dVue]);
break;
case 'join':
@ -39,7 +55,7 @@ class FrontController
$this->ValidationFormulaire($dVueErreur, $dVue);
break;
case 'admin':
new AdminController();
new AdminController($action);
break;
case 'login':
if(empty($_SESSION) && !isset($_REQUEST['login']))
@ -76,7 +92,7 @@ class FrontController
echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]);
echo $twig->render('login.html');
} catch (\Exception $e2) {
$dVueErreur[] = 'Erreur inattendue !';
$dVueErreur[] = 'Erreur inattendue !'.$e2->getMessage();
echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]);
}

@ -11,9 +11,16 @@
'cache' => false,
]);
//altorouter
$router = new AltoRouter();
$router->setBasePath('/public_html/ScienceQuest');
$cont = new FrontController();
/*
try{
$con=new model\Connection($dsn,$login,$mdp);

Loading…
Cancel
Save