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
- Model — works with the database
- View — the HTML page
- 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.