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 | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/index.php b/index.php index e69de29..9ebc44a 100644 --- a/index.php +++ b/index.php @@ -0,0 +1,22 @@ +<?php + +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("/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); + +$dispatcher->handle($path); + \ No newline at end of file -- Gitblit v1.8.0