A Controller in CodeIgniter acts as the middle layer between the Model and the View. It receives user requests, processes data, and returns a response.
Handles HTTP requests
Calls models to fetch/update data
Loads views or returns responses (JSON, text, etc.)
Controls application flow
Configured in:
Access:
View file:
Route:
Apply authentication or validation filters.
Provides methods:
index()
show($id)
create()
update($id)
delete($id)
✅ Keep controllers thin
✅ Move logic to Models/Services
✅ One responsibility per controller
❌ Avoid database logic directly in controllers
Controllers handle user requests
Stored in app/Controllers
Communicate with Models & Views
Support views, JSON, redirects, APIs
Take quizzes related to this topic and see where you stand!
Start Quiz Now