June 10, 2026
What are controllers in CodeIgniter
Controllers are very important in CodeIgniter project. It contains complete project's business logic. Controllers also works as a mediator between models (database classes) and views (HTML UIs). Controllers are bind with URLs, so whenever a user hits a URL based on URL and controllers mapping, appropriate controller function and classed gets called. Every controller in controller must be extended with CI_Controller controller class. Examples of views are mentioned below
class Students extends CI_Controller {
public function index() {
$this->load->model('Student_model');
$data['student_detail'] = $this->Student_model->get_student_details($id);
$this->load->view('student_details', $data);
}
}
FAQ
1. Benefits of controller?
Complete business logic should be written in controller part. The Controller connects the View and the Model. It handles user requests, gets data from the Model, and sends the response to the View for display.
2. Who write code in controller?
Developers should implement business logic code in controller part. DBA should write database related code in model.