Models in CodeIgniter — a practical guide to CodeIgniter models with clear examples you can reuse in real projects.
CodeIgniter Tutorial Series (35/74). Prefer one article? Read the complete CodeIgniter tutorial.
Short description
CI4 models provide `find`, `save`, `insert`, `update`, and `delete` with protection via `$allowedFields`.
Basic model
<?php
namespace AppModels;
use CodeIgniterModel;
class PostModel extends Model
{
protected $table = 'posts';
protected $primaryKey = 'id';
protected $allowedFields = ['title', 'body', 'user_id'];
protected $useTimestamps = true;
}