What are models in CodeIgniter

Models are very important in CodeIgniter. We perform database related operation by using model classes. In CodeIgniter we extent all the model class with CI_Model class (It is CodeIgniter's build-in class). Ideally we should create one model class for one table, which makes are code more cleaner and easy to maintain. Controllers interact with model classes to retrieve and save data into database. We should create model class in application/models/ folder. Example of model class is mentioned below: Model Class Sample


<?php
//Student_model.php  model class
class Student_model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    public function get_student_details($id) {
        return $this->db->get_where('students', ['id' => $id])->row();
    }

    public function insert_student_records($data) {
        return $this->db->insert('students', $data);
    }
}
To see how to load a model class in CodeIgniter project, please click here