PHP Classes

File: public/index.php

Recommend this page to a friend!
  Classes of Rodrigo Faustino   PHP MVC App   public/index.php   Download  
File: public/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP MVC App
MVC based application for the Web and as an API
Author: By
Last change:
Date: 12 days ago
Size: 606 bytes
 

Contents

Class file image Download
<?php
session_start
();

require_once
'../vendor/autoload.php';
require_once
'./routes.php';
use
App\core\Router;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__. '/../');
$dotenv->load();

$route = $router->resolve($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);

if (
$route) {
   
$controllerName = "App\\Controllers\\" . $route['controller'];
   
$action = $route['action'];
   
$params = $route['params'] ?? [];

   
$controller = new $controllerName();

   
call_user_func_array([$controller, $action], $params);
} else {
   
http_response_code(404);
    require
'../app/Views/errors/404.php';
}