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 |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/index.php b/index.php
index 32bb1da..4d33eda 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,7 @@
 <?php
-require "src/router.php";
+spl_autoload_register(function ($class) {
+    require "src/$class.php";
+ });
 
 $path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
 $segments = explode("/", $path);
@@ -9,8 +11,13 @@
 $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"];
 

--
Gitblit v1.8.0