agyanadda@gmail.com

CodeIgniter 4 Introduction

CodeIgniter 4 Basics 1 min read Updated Dec 3, 2026 Topic 1 of 30

CodeIgniter 4 (CI4) is a free, open-source PHP framework for building websites and web applications. It is known for being small, fast and easy to learn.

Why use CodeIgniter?

  • Lightweight — small footprint and very fast
  • Simple to learn — little configuration and clear documentation
  • MVC structure — keeps your code organised
  • Built-in tools — routing, Query Builder, validation, sessions, email, caching, file uploads
  • Security features — CSRF protection, output escaping, XSS filtering helpers
  • Runs on almost any hosting, including cheap shared hosting

The MVC pattern

  1. Model — works with the database
  2. View — the HTML page
  3. Controller — receives the request, uses models and loads views

CodeIgniter 3 vs 4

CI4 is a complete rewrite: it uses namespaces, Composer, PSR-4 autoloading, a public folder as the web root, the spark command-line tool, migrations, filters and modern PHP 8. CI3 code does not run on CI4 without changes.

Before you start

Know basic PHP (including classes), HTML and a little SQL.

Example

Example — Your first CodeIgniter page PHP
<?php
// app/Config/Routes.php
$routes->get('hello', 'Hello::index');

// app/Controllers/Hello.php
namespace App\Controllers;

class Hello extends BaseController
{
    public function index()
    {
        return 'Hello from CodeIgniter 4!';
    }
}

Open http://localhost:8080/hello and the browser shows: Hello from CodeIgniter 4! A route points the URL to a controller method.

Test Yourself With Exercises

Exercise 1 Multiple Choice

What is CodeIgniter 4?

Exercise 2 True / False

CodeIgniter 3 code runs on CodeIgniter 4 without any changes.

Exercise 3 Fill in the Blank

CodeIgniter 4's command-line tool is called ___.

Frequently Asked Questions

Both are good PHP frameworks. CodeIgniter is smaller and quicker to learn, and it runs well on basic hosting. Laravel has a larger ecosystem and more jobs in big companies. Many developers learn CodeIgniter first and Laravel later, and the MVC ideas carry over.