From ed1f744e1cf0045540c2e6349cc7dcc5031c8652 Mon Sep 17 00:00:00 2001 From: filippo.bertilotti <filippobertilotti@gmail.com> Date: Tue, 14 May 2024 11:38:23 +0200 Subject: [PATCH] (parte 86) --- index.php | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-) diff --git a/index.php b/index.php index 6a9577d..f38c0a8 100644 --- a/index.php +++ b/index.php @@ -8,21 +8,17 @@ $segments = explode("/", $path); $router = new Framework\Router; + +$router->add("/admin/{controller}/{action}", ["namespace" => "Admin"]); +$router->add("/product/{slug:[\w-]+}", ["controller" => "products", "action" => "show"]); +$router->add("/{title}/{id:\d+}/{page:\d+}", ["controller" => "products", "action" => "showPage"]); +$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