🔥 CodeIgniter Intermediate

What is CI4's auto-routing improved?

Why Interviewers Ask This

This question targets practical, hands-on experience with CodeIgniter. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

Answer

Auto Routing Improved (CI4.2+) is a safer version of auto-routing that maps URLs to controller methods without requiring explicit route definitions. Enable: $routes->setAutoRoute(true) in app/Config/Routes.php. URL: /controller/method/param maps to Controller::method($param). Key security improvements over the old auto-routing: only methods explicitly prefixed with the HTTP verb are accessible (getIndex() for GET, postStore() for POST), parent class methods are not accessible, the method must accept the correct number of parameters. This prevents accidental exposure of internal methods. The route list: php spark routes shows all accessible auto-routes. For new projects, explicit routes are still recommended for clarity, but Auto Routing Improved is a much safer option than the original CI3/CI4 auto-routing for rapid development.

Pro Tip

This topic has CodeIgniter-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.