From f6df29226eaad3c37245b8774de6639acf589b1d Mon Sep 17 00:00:00 2001
From: filippo.bertilotti <filippobertilotti@gmail.com>
Date: Fri, 10 May 2024 11:23:50 +0200
Subject: [PATCH] refactor code index dispatcher (parte 64)

---
 index.php |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/index.php b/index.php
index ade8989..9ebc44a 100644
--- a/index.php
+++ b/index.php
@@ -9,22 +9,14 @@
 
 $router = new Framework\Router;
 
-$router->add("/{controller}/{action}");
+$router->add("/product/{slug:[\w-]+}", ["controller" => "products", "action" => "show"]);
+$router->add("/{controller}/{id:\d+}/{action}");
 $router->add("/home/index", ["controller" => "home", "action" => "index"]);
 $router->add("/products", ["controller" => "products", "action" => "index"]);
 $router->add("/", ["controller" => "home", "action" => "index"]);
+$router->add("/{controller}/{action}");
 
+$dispatcher = new Framework\Dispatcher($router);
 
-$params = $router->match($path);
-
-if($params === false) {
-    exit("No routes matched");
-}
-
-$controller = "App\Controllers\\" . ucwords($params["controller"]);
-$action = $params["action"];
-
-$controller_object = new $controller;
-
-$controller_object->$action();
+$dispatcher->handle($path);
     
\ No newline at end of file

--
Gitblit v1.8.0