From e2903b7b32aa672c9d821b0b18d26c20db5b00f4 Mon Sep 17 00:00:00 2001 From: filippo.bertilotti <filippobertilotti@gmail.com> Date: Fri, 10 May 2024 09:45:32 +0200 Subject: [PATCH] correzione regular expression per permettere di accettare tutti i caratteri tranne "/" (parte 58) --- index.php | 36 +++++++++++++++++++++++++++++++----- 1 files changed, 31 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 6d5a3fb..dbfa428 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,33 @@ <?php - require "model.php"; - - $model = new Model; - $products = $model->getData(); - require "view.php"; \ No newline at end of file +spl_autoload_register(function ($class) { + require "src/". str_replace("\\", "/", $class). ".php"; + }); + +$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); +$segments = explode("/", $path); + +$router = new Framework\Router; + +$router->add("/{controller}/{action}"); +$router->add("/{controller}/{id}/{action}"); +$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); + +print_r($params); + +if($params === false) { + exit("No routes matched"); +} + +$controller = "App\Controllers\\" . ucwords($params["controller"]); +$action = $params["action"]; + +$controller_object = new $controller; + +$controller_object->$action(); + \ No newline at end of file -- Gitblit v1.8.0