corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-07 b62315aee0d26f98b1c1db083dae4ae73a110fad
index.php
@@ -1,13 +1,29 @@
<?php
spl_autoload_register(function ($class) {
    require "src/$class.php";
 });
require "src/controllers/products.php";
$controller = new Products;
$action = $_GET["action"];
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
$segments = explode("/", $path);
$router = new Router;
$router->add("/home/index", ["controller" => "home", "action" => "index"]);
$router->add("/products", ["controller" => "products", "action" => "index"]);
$router->add("/", ["controller" => "home", "action" => "index"]);
if($action === "index") {
    $controller->index();
}elseif($action === "show") {
    $controller->show();
$params = $router->match($path);
if($params === false) {
    exit("No routes matched");
}
$controller = $params["controller"];
$action = $params["action"];
require "src/controllers/$controller.php";
$controller_object = new $controller;
$controller_object->$action();