From 0011752c10c2aa6b599b0570865c61d6bc68e880 Mon Sep 17 00:00:00 2001 From: filippo.bertilotti <filippobertilotti@gmail.com> Date: Tue, 07 May 2024 09:59:46 +0200 Subject: [PATCH] divisione dell'url in segmenti per la creazione di url piĆ¹ carine (parte 22/23) --- index.php | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index 98326de..95daf7b 100644 --- a/index.php +++ b/index.php @@ -1,13 +1,14 @@ <?php -require "src/controllers/products.php"; -$controller = new Products; -$action = $_GET["action"]; +$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); +$segments = explode("/", $path); +$controller = $segments[1]; +$action = $segments[2]; -if($action === "index") { - $controller->index(); -}elseif($action === "show") { - $controller->show(); -} +require "src/controllers/$controller.php"; + +$controller_object = new $controller; + +$controller_object->$action(); \ No newline at end of file -- Gitblit v1.8.0