You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.7 KiB
66 lines
2.7 KiB
<?php
|
|
|
|
namespace controllers;
|
|
|
|
use controllers\ControllerUser;
|
|
use \Exception;
|
|
use usages\AltoRouter;
|
|
|
|
class FrontController
|
|
{
|
|
function __construct()
|
|
{
|
|
global $vues;
|
|
|
|
try {
|
|
// Initialize AltoRouter
|
|
$router = new AltoRouter();
|
|
|
|
//$router->setBasePath('/');
|
|
|
|
// Define routes
|
|
$router->map('GET', '/', 'ControllerUser#home'); // Route pour la page d'accueil
|
|
$router->map('GET', '/error', 'ControllerUser#error'); // Route pour la page d'erreur
|
|
$router->map('GET|POST', '/[a:action]', 'ControllerUser');
|
|
//$router->map('GET', '/admin', 'ControllerAdminAdministrators');
|
|
$router->map('POST', '/login/[a:action]', 'ControllerUser');
|
|
$router->map('GET', '/admin/chapters', 'ControllerAdminChapters');
|
|
$router->map('POST', '/admin/chapters/[a:action]', 'ControllerAdminChapters');
|
|
$router->map('GET', '/admin/chapters/[a:action]/[i:id]', 'ControllerAdminChapters');
|
|
$router->map('GET', '/admin/administrators', 'ControllerAdminAdministrators');
|
|
$router->map('POST', '/admin/administrators/[a:action]', 'ControllerAdminAdministrators');
|
|
$router->map('GET', '/admin/administrators/[a:action]/[i:id]', 'ControllerAdminAdministrators');
|
|
$router->map('GET', '/admin/questions', 'ControllerAdminQuestions');
|
|
$router->map('POST', '/admin/questions/[a:action]', 'ControllerAdminQuestions');
|
|
$router->map('GET', '/admin/questions/[a:action]/[i:id]', 'ControllerAdminQuestions');
|
|
$router->map('GET', '/lobby/list', 'ControllerUserLobby');
|
|
$router->map('POST', '/user/players/[a:action]', 'ControllerUserPlayers');
|
|
$router->map('GET', '/user/players/[a:action]/[i:id]', 'ControllerUserPlayers');
|
|
|
|
// Match the current request
|
|
$match = $router->match();
|
|
|
|
if (!$match) {
|
|
echo "404"; // Redirige vers une page d'erreur 404
|
|
die;
|
|
}
|
|
|
|
if ($match) {
|
|
$controller = $match['target'];
|
|
if (strpos($controller, "#") !== false) {
|
|
list($controller, $action) = explode("#", $controller);
|
|
} else {
|
|
$action = $match['params']['action'];
|
|
$id = $match['params']['id'];
|
|
}
|
|
$controller = new ("controllers\\".$controller)();
|
|
if (is_callable(array($controller, $action))) {
|
|
call_user_func_array(array($controller, $action), array($match['params']));
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
header("Location:" . $vues["erreur"]);
|
|
}
|
|
}
|
|
}
|