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 | 30 +++++++++++++++++++++--------- 1 files changed, 21 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index 2ca28b7..f38c0a8 100644 --- a/index.php +++ b/index.php @@ -1,12 +1,24 @@ <?php - $dns = "mysql:host=localhost;dbname=product_db;charset=utf8;port=3306"; - $pdo = new PDO($dns, "product_db_user", "secret", [ - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION - ]); - $stmt = $pdo->query("SELECT * FROM product"); +spl_autoload_register(function ($class) { + require "src/". str_replace("\\", "/", $class). ".php"; + }); - $products = $stmt->fetchAll(PDO::FETCH_ASSOC); - - print_r($products); -?> \ No newline at end of file +$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); +$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); + +$dispatcher->handle($path); + \ No newline at end of file -- Gitblit v1.8.0