// Retrieve the current controller from the request URL $controller = $_GET['controller']; // Load the appropriate controller and execute its method include_once('controllers/' . $controller . '.php'); $controllerInstance = new $controller(); $controllerInstance->execute();
// Use a package or library to retrieve the current controller use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); $controller = $request->query->get('controller'); // Load and execute the controller as beforeIn this example, we're using the Symfony HttpFoundation package to handle the request and retrieve the controller parameter. The advantage of using a package or library like this is that it provides more robust handling of the request and makes the code more modular and reusable.