What is a Model in CodeIgniter 4?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for CodeIgniter development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
CodeIgniter 4 ships with a powerful Model class that provides a rich set of database interaction methods. Extend CodeIgniter\Model and configure the model with properties: protected $table = "users", protected $primaryKey = "id", protected $allowedFields = ["name", "email", "password"], protected $useTimestamps = true. The model provides: find($id), findAll(), where("active", 1)->findAll(), insert($data), update($id, $data), delete($id). It also has built-in validation via the $validationRules property and business rule callbacks (beforeInsert, afterFind, etc.). CI4 models are lighter than Laravel's Eloquent but sufficient for most use cases.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong CodeIgniter candidates.