• Call Us: +92-333-7276335
  • - Mail Us: info@shekztech.com

Plot 1177, Sector 31B - Crossing, Karachi, Sindh

Creating the model in codeigniter 4

Creating the model in Codeigniter 4

Creating the model in Codeigniter 4 is different from Codeigniter 3; in CodeIgniter 3, you always define the whole body of the method, but here in Codeigniter 4, you don't need to define the entire function. Just configure the table with your Codeigniter 4 and pass some variables. That's it; now you are ready to go. In this lesson, you will learn how to create the model in Codeigniter 4.

<?php namespace AppModels;
use CodeIgniterModel;

class MyStudents extends Model
{
  protected $DBGroup = 'default';

  protected $table = 'students';
  protected $primaryKey = 's_id';
  protected $returnType = 'array';
  protected $useTimestamps = true;
  protected $allowedFields = ['s_name','s_date','s_subject','s_update'];
  protected $createdField = 's_date';
  protected $updatedField = 's_update';

}