What is CodeIgniter 4 named routes and URL generation?

Why Interviewers Ask This

Senior CodeIgniter engineers are expected to reason about architecture, performance, and edge cases. This question separates mid-level from senior candidates by testing deep system-level understanding.

Answer

CodeIgniter 4 supports named routes for generating URLs by name instead of hardcoding paths. Assign names in app/Config/Routes.php: $routes->get("users/(:num)", "UserController::show/$1", ["as" => "user.show"]). Generate URLs by name: route_to("user.show", 42) returns /users/42. In views: <a href="<?= route_to("user.show", $user->id) ?>">View</a>. Reverse routing also works with controller::method notation: route_to("UserController::show", $id). Redirect to named route: return redirect()->route("user.show", [$id]). Named routes decouple views and controllers from URL structures — change the URL in one place and all generated links automatically update. This is especially valuable in large applications and when implementing URL slugs or localized URLs that change per-language.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last CodeIgniter project, I used this when...' immediately makes your answer more credible and memorable.