corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-10 f6df29226eaad3c37245b8774de6639acf589b1d
index.php
@@ -1,13 +1,22 @@
<?php
require "src/controllers/products.php";
$controller = new Products;
$action = $_GET["action"];
spl_autoload_register(function ($class) {
    require "src/". str_replace("\\", "/", $class). ".php";
 });
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
$segments = explode("/", $path);
if($action === "index") {
    $controller->index();
}elseif($action === "show") {
    $controller->show();
}
$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);