Routing in CodeIgniter
📘 CodeIgniter
👁 26 views
📅 Dec 22, 2025
⏱ Estimated reading time: 2 min
Routing defines how URLs are mapped to controllers and methods. In CodeIgniter 4, routing is powerful, flexible, and easy to configure.
1. Where Routes Are Defined
Routes are defined in:
2. Basic Route Syntax
Example
URL:
3. HTTP Method-Based Routing
4. Route with Parameters
Numeric Parameter
URL:
Any String Parameter
URL:
5. Default Controller & Method
Set in Routes.php:
6. Route Groups
Useful for organizing routes.
URL:
7. Named Routes
Generate URL:
8. Auto Routing
Enable (Not Recommended for Production)
Allows:
⚠️ Security Risk – better to define routes manually.
9. Redirect Routes
10. Route Filters (Middleware)
Apply filters like authentication.
Or group filter:
11. RESTful Resource Routing
Automatically creates CRUD routes.
Creates:
-
GET
/users -
POST
/users -
GET
/users/{id} -
PUT
/users/{id} -
DELETE
/users/{id}
12. Example Controller
Summary
-
Routes map URLs → Controllers
-
Defined in
app/Config/Routes.php -
Supports parameters, groups, filters, REST APIs
-
Avoid auto-routing in production
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials