| | |
| | | <?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(); |
| | | |