What is Routing in CodeIgniter 4?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid CodeIgniter basics — a prerequisite for any developer role.
Answer
CodeIgniter 4 routing is defined in app/Config/Routes.php. Routes map URL patterns to controller methods: $routes->get("users", "UserController::index"). HTTP verb methods: get(), post(), put(), patch(), delete(), match(). URL parameters: $routes->get("users/(:num)", "UserController::show/$1") — (:num), (:alpha), (:alphanum), (:any), (:segment) are built-in placeholders. Named routes: $routes->get("users", "UserController::index", ["as" => "users.index"]). Generate URL by name: route_to("users.index"). CI4's auto-routing (off by default) can map URLs directly to controllers without explicit route definitions — but explicit routes are safer and recommended.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex CodeIgniter answers easy to follow.