We use cookies

We use cookies to make this site work well and to understand how it's used. See our privacy policy and terms of service.

ESC

Search

Newsletter

Subscribe to our newsletter

New masterclasses, tech articles, and college-portal updates — no spam.

We don't spam, ever.

Back to Tools

CodeIgniter 4 Architecture & Syntax Cheat Sheet

Quick reference guide for Models, Query Builder, Route groups, Filters, and CSRF protection in CodeIgniter 4.

Routes & Filters app/Config/Routes.php
$routes->group('student', ['filter' => 'auth'], static function ($routes) {
    $routes->get('dashboard', 'Student\DashboardController::index');
    $routes->get('course/(:segment)', 'Student\PlayerController::play/$1');
});
Query Builder (Fluent SQL) Model / Controller
$users = $db->table('users')
    ->select('users.*, subscriptions.status as sub_status')
    ->join('subscriptions', 'subscriptions.user_id = users.id', 'left')
    ->where('users.role', 'student')
    ->orderBy('users.id', 'DESC')
    ->limit(20)
    ->get()
    ->getResultArray();
CSRF Token Form Views
<form action="<?= base_url('submit') ?>" method="POST">
    <?= csrf_field() ?>
    <input type="text" name="name" required>
    <button type="submit">Submit</button>
</form>
Model Structure app/Models/UserModel.php
class UserModel extends Model {
    protected $table = 'users';
    protected $primaryKey = 'id';
    protected $allowedFields = ['name', 'email', 'password', 'role', 'status'];
    protected $useTimestamps = true;
    protected $dateFormat = 'datetime';
}

Want to master CodeIgniter 4 & Full-Stack Monolith Architecture?

Watch our complete video masterclass taking you from zero to production SaaS deployment.

Unlock Full Monolith Masterclass ($2.99) →
Need Help? 👋
Chat with mentors online
DigitalStudy Support
Live Admin & AI Desk • Online Now

Leave contact so mentors can follow up:

Never Break Your Learning Streak

Get 1 daily nudge when your coding streak is at risk.