How does the use of a Front Controller in PHP affect the distribution of requests to specific controllers in a MVC architecture?
The use of a Front Controller in PHP centralizes the handling of incoming requests and routes them to the appropriate controller based on the request parameters or URI. This helps in better organizing the code and ensures that the requests are distributed to specific controllers in a consistent manner in a MVC architecture.
// index.php (Front Controller)
$request = $_SERVER['REQUEST_URI'];
if ($request === '/home') {
require 'controllers/HomeController.php';
$controller = new HomeController();
$controller->index();
} elseif ($request === '/about') {
require 'controllers/AboutController.php';
$controller = new AboutController();
$controller->index();
} else {
echo '404 - Page not found';
}