From b62315aee0d26f98b1c1db083dae4ae73a110fad Mon Sep 17 00:00:00 2001 From: filippo.bertilotti <filippobertilotti@gmail.com> Date: Tue, 07 May 2024 11:29:57 +0200 Subject: [PATCH] implementazione autoload delle class necessarie (parte 30) --- index.php | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 95daf7b..4d33eda 100644 --- a/index.php +++ b/index.php @@ -1,10 +1,25 @@ <?php +spl_autoload_register(function ($class) { + require "src/$class.php"; + }); $path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); $segments = explode("/", $path); -$controller = $segments[1]; -$action = $segments[2]; +$router = new Router; +$router->add("/home/index", ["controller" => "home", "action" => "index"]); +$router->add("/products", ["controller" => "products", "action" => "index"]); +$router->add("/", ["controller" => "home", "action" => "index"]); + + +$params = $router->match($path); + +if($params === false) { + exit("No routes matched"); +} + +$controller = $params["controller"]; +$action = $params["action"]; require "src/controllers/$controller.php"; -- Gitblit v1.8.0