Challenge 1 — Solution Task: Add a second route to the Router example: GET /about, mapped to a new AboutController with a show() method that requires a simple views/about.php containing static "About us" text (no model needed). Trace through, in writing, exactly what happens from the request hitting index.php to the final HTML being produced. ---- src/Controllers/AboutController.php ---- About Us

This is a small demonstration application built to learn MVC.

---- public/index.php (updated) ---- get('/posts', [PostController::class, 'index']); $router->get('/about', [AboutController::class, 'show']); $uri = strtok($_SERVER['REQUEST_URI'], '?'); $router->dispatch($uri); ?> ---- Trace: a request to GET /about ---- 1. The web server routes every request to public/index.php (the front controller), regardless of the actual URL path requested. 2. index.php loads Composer's autoloader, then registers two routes on a new Router instance: '/posts' and '/about', each mapped to a [ControllerClass, 'method'] pair. 3. strtok($_SERVER['REQUEST_URI'], '?') extracts just the path portion of the URL ("/about"), stripping away any query string like "?foo=bar" that might follow it. 4. $router->dispatch('/about') is called. Inside dispatch(), isset() checks whether '/about' exists as a registered route key - it does, so the 404 branch is skipped. 5. [$controllerClass, $method] destructures the stored handler into "App\Controllers\AboutController" and "show". 6. new $controllerClass() dynamically instantiates a real AboutController object, using the class name stored in a variable rather than written literally. 7. $controller->$method() dynamically calls show() on that object. 8. Inside show(), a plain require pulls in views/about.php directly - since this route needs no data at all, there's no Model step this time, just Controller -> View. 9. views/about.php's own static HTML (

About Us

etc.) is echoed directly as it's required, becoming the final response body sent back to the browser. Notes: - This route deliberately has no Model at all, showing that MVC's three roles are the available structure, not a mandatory checklist - a route with no real data needs no Model step. - The dynamic new $controllerClass() / $controller->$method() pattern from Router.php works identically for AboutController as it did for PostController, without the Router class itself needing any changes to support a second, unrelated controller.