Frameworks like Laravel and Symfony are built on the same core idea: separating a request into a Model (data), View (presentation), and Controller (logic). Building a tiny MVC skeleton yourself demystifies what a framework is actually doing for you.
// A minimal front controller
$route = $_GET['route'] ?? 'home';
$routes = [
'home' => [HomeController::class, 'index'],
'users' => [UserController::class, 'list'],
];
[$controllerClass, $method] = $routes[$route] ?? [ErrorController::class, 'notFound'];
$controller = new $controllerClass();
$controller->$method();
class UserController {
public function list(): void {
$users = (new UserModel())->getAll();
require __DIR__ . '/views/users.php'; // the View
}
}
This is deliberately minimal — real frameworks add routing with parameters, middleware, dependency injection, and much more — but the core loop (route request → controller → model → view) is exactly what’s happening underneath every PHP MVC framework you’ve used.