Table of Contents
“ CodeIgniter is a free, open-source PHP framework for building websites, web apps, and REST APIs. It follows the Model-View-Controller (MVC) pattern, runs fast with a very small footprint, and is easy to learn. The current version, CodeIgniter 4, uses modern PHP (version 4.7 requires PHP 8.2 or higher). It is a great fit for small to mid-size projects, while Laravel suits teams that want more built-in tools.
If you have ever wanted to build a PHP web app without learning a huge framework first, CodeIgniter is worth a look. It gives you clean structure, built-in security, and helpful tools, while staying out of your way.
This guide explains what CodeIgniter is, how a request moves through it, the features that matter most, real code examples, honest pros and cons, and how it compares to Laravel and Symfony.
What Is CodeIgniter?
CodeIgniter is a PHP framework: a ready-made foundation of code that handles common tasks like routing URLs, talking to databases, validating forms, and protecting against attacks. Instead of writing all of that from scratch, developers focus on the features that make their app unique.
Three things define CodeIgniter:
- It is lightweight. The core download is small, and it loads only what each request needs.
- It is simple. It has few rules and very little “magic”, so code is easy to read and debug.
- It is fast. Low overhead means quick response times, even on basic shared hosting.
CodeIgniter is written in PHP, the language behind a large share of the web, so it runs on almost any hosting provider.
A Short History of CodeIgniter
| Year | Milestone |
|---|---|
| 2006 | First released by EllisLab |
| 2014 | Ownership moved to the British Columbia Institute of Technology (BCIT) |
| 2019 | The CodeIgniter Foundation took over the project |
| 2020 | CodeIgniter 4.0 launched, a full rewrite for modern PHP |
| 2026 | CodeIgniter 4.7 released, requiring PHP 8.2 or higher |
This long history matters. CodeIgniter has been used in production for about 20 years, and it is still actively maintained, with regular releases and security fixes.
How CodeIgniter Works: The Request Flow
Every time someone visits a page in a CodeIgniter app, the request follows the same simple path:
- The request arrives at public/index.php. This is the single front door for the whole app. CodeIgniter starts up and loads your settings.
- The router picks a controller. It matches the URL, like /products/42, to a controller method, like Products::show(42).
- Filters run (optional). Filters are small checks that run before or after the controller, such as “is this user logged in?” or “add security headers”.
- The controller does the work. It reads the request, calls models or services, and decides what to send back.
- The model talks to the database. It finds, saves, updates, or deletes records, and validates data before saving.
- The view builds the output. It turns data into HTML, or the controller returns JSON for an API.
- The response goes back to the browser. Caching can store the result so the next visitor gets it even faster.
What MVC Means in Plain English
| Part | Job | Example |
|---|---|---|
| Model | Handles data and business rules | Gets product 42 from the database and checks the price is valid |
| View | Shows information to the user | The HTML page that displays the product name, photo, and price |
| Controller | Connects the two | Receives the request, asks the model for the product, and sends it to the view |
Keeping these three jobs separate makes code easier to test, change, and hand over to another developer.
Key Features of CodeIgniter 4
| Feature | What it does | Why it helps |
|---|---|---|
| Routing | Maps clean URLs to controller methods, with groups and filters | SEO-friendly URLs and clear app structure |
| Models and Query Builder | Simple database methods like find(), insert(), and where() | Less raw SQL, safer queries |
| Entities | Lightweight objects that represent a database row | Cleaner, more readable data handling |
| Validation | Built-in rules like required, valid_email, and max_length | Stops bad data before it reaches the database |
| Filters | Code that runs before or after controllers | Handles login checks, CORS, and rate limits in one place |
| Security tools | CSRF protection, output escaping, Content Security Policy support | Protects against common web attacks |
| Caching | File, Redis, and Memcached drivers, plus page caching | Faster pages and lower server load |
| RESTful resources | Resource routes and ResourceController | Build JSON APIs quickly |
| Spark CLI | Command-line tool for migrations, seeders, and code generation | Saves time on repetitive tasks |
| Debug Toolbar | Shows queries, timing, and variables during development | Find slow queries and bugs fast |
| Testing support | Built on PHPUnit with helpers for HTTP and database tests | Easier automated testing |
| CodeIgniter Shield | Official authentication and authorization library | Logins, sessions, API tokens, and roles without starting from scratch |
What CodeIgniter does not include: a full ORM like Laravel’s Eloquent or Symfony’s Doctrine. It uses the Query Builder and Entities instead, which many developers find simpler. If you need a full ORM, you can add one with Composer.
CodeIgniter Code Examples
These short examples show how little code a typical feature takes.
1. Install and Run a New Project
composer create-project codeigniter4/appstarter my-app
cd my-app
php spark serve
Open http://localhost:8080 and you will see the CodeIgniter welcome page.
2. Define a Route
In app/Config/Routes.php:
$routes->get('products/(:num)', 'Products::show/$1');
3. Create a Model
In app/Models/ProductModel.php:
<?php
namespace App\Models;
use CodeIgniter\Model;
class ProductModel extends Model
{
protected $table = 'products';
protected $allowedFields = ['name', 'price'];
protected $useTimestamps = true;
protected $validationRules = [
'name' => 'required|max_length[100]',
'price' => 'required|decimal',
];
}
4. Create a Controller
In app/Controllers/Products.php:
<?php
namespace App\Controllers;
use App\Models\ProductModel;
use CodeIgniter\Exceptions\PageNotFoundException;
class Products extends BaseController
{
public function show(int $id)
{
$product = model(ProductModel::class)->find($id);
if ($product === null) {
throw PageNotFoundException::forPageNotFound();
}
return view('products/show', ['product' => $product]);
}
}
5. Build a REST API Endpoint
One line of routing creates all the standard CRUD routes:
$routes->resource(‘users’);
Then extend ResourceController:
<?php
namespace App\Controllers;
use CodeIgniter\RESTful\ResourceController;
class Users extends ResourceController
{
protected $modelName = 'App\Models\UserModel';
protected $format = 'json';
public function index()
{
return $this->respond($this->model->findAll());
}
}
This returns a JSON list of users at GET /users. Add show, create, update, and delete methods the same way. New to APIs? Our guide on what API development is covers the basics.
CodeIgniter Folder Structure
| Folder | What goes there |
|---|---|
| app/Config | Settings for the database, routes, filters, and more |
| app/Controllers | Your controllers |
| app/Models | Your models |
| app/Views | HTML templates |
| app/Filters | Custom filters, like login checks |
| public/ | The web root: index.php, CSS, JavaScript, and images |
| writable/ | Cache, logs, sessions, and uploads |
| tests/ | Automated tests |
| vendor/ | Composer packages, including the framework itself |
Only the public/ folder should be visible to the web. Pointing your server’s document root at the project folder instead is one of the most common, and most dangerous, setup mistakes.
Pros and Cons of CodeIgniter
| Pros | Cons |
|---|---|
| Very fast, with low memory use | Smaller package ecosystem than Laravel |
| Small learning curve, great docs | No full ORM built in |
| Runs on cheap shared hosting | Fewer built-in features for queues, broadcasting, and admin panels |
| Little “magic”, so code is easy to follow | Smaller US job market and community than Laravel |
| Flexible: few strict conventions | That flexibility means teams must set their own code standards |
| Long track record and active maintenance | Many older tutorials still show CodeIgniter 3, which can confuse beginners |
CodeIgniter vs Laravel vs Symfony
| CodeIgniter 4 | Laravel | Symfony | |
|---|---|---|---|
| Best for | Small to mid-size apps, APIs, fast builds | Full-featured web apps and SaaS products | Large, complex enterprise systems |
| Learning curve | Easy | Moderate | Steeper |
| Speed and footprint | Very light | Heavier, but well optimized | Heavier, highly configurable |
| Database layer | Query Builder and Entities | Eloquent ORM | Doctrine ORM |
| Built-in extras | Core essentials plus Shield for auth | Queues, events, mail, scheduling, starter kits | Reusable components for nearly everything |
| Ecosystem size | Smaller | Largest in PHP | Large |
| Hosting needs | Works on basic shared hosting | Usually a VPS or managed host | Usually a VPS or managed host |
Simple rule: Choose CodeIgniter for speed, simplicity, and small teams. Choose Laravel when you want more features out of the box. Choose Symfony for very large, long-term enterprise systems. For a deeper look, read our full comparison of Laravel vs other PHP frameworks.
When Should You Use CodeIgniter?
CodeIgniter is a great choice for:
- Business dashboards, client portals, and internal tools.
- REST APIs that power mobile apps or JavaScript front ends like React or Vue.
- Small to mid-size ecommerce catalogs and booking systems.
- Projects on a tight budget or basic hosting.
- Teams new to PHP frameworks who want quick results.
Consider another framework when:
- You need many built-in features like queues, real-time broadcasting, or admin panels.
- You want the largest pool of packages and developers to hire from.
- You are building a very large system with many teams and strict conventions.
Still on CodeIgniter 3? Plan Your Upgrade
CodeIgniter 3 is the older generation and no longer gets new features. It was built for older PHP versions, so running it on modern, supported PHP can cause errors and security gaps.
CodeIgniter 4 is not a simple update. It is a rewrite, with namespaces, Composer, and a new folder structure, so plan the move like a migration:
- Audit your current app: controllers, models, libraries, and custom helpers.
- Set up a fresh CodeIgniter 4 project on a supported PHP version.
- Move code in small pieces, starting with models and shared libraries.
- Rewrite routes, since CodeIgniter 4 favors defined routes over auto-routing.
- Test each section before moving the next, then switch traffic over.
Conclusion
CodeIgniter is a fast, lightweight PHP framework that gets out of your way. It is easy to learn, runs almost anywhere, and still covers the essentials: routing, database tools, validation, security, caching, and APIs. For small to mid-size apps, internal tools, and APIs, it is one of the most practical choices in PHP today.
Frequently Asked Questions
Is CodeIgniter still used in 2026?
Yes. CodeIgniter 4 is actively maintained by the CodeIgniter Foundation, with regular releases and security fixes. Version 4.7 arrived in early 2026 with new features such as controller attributes and enum support.
What PHP version does CodeIgniter 4 need?
CodeIgniter 4.7 requires PHP 8.2 or higher. If you are stuck on PHP 8.1, the 4.6 branch still works, but plan to upgrade PHP soon. Always check the official user guide for the latest requirement before starting a project.
Is CodeIgniter better than Laravel?
Neither is better for every project. CodeIgniter is lighter, faster to learn, and easier to host. Laravel has more built-in features and a bigger ecosystem. Pick CodeIgniter for simpler apps and APIs, and Laravel for feature-rich products.
Is CodeIgniter good for beginners?
Yes. It is one of the easiest PHP frameworks to learn because it has clear documentation, simple structure, and very little hidden behavior.
Can I build REST APIs with CodeIgniter?
Yes. Resource routes and ResourceController let you build JSON APIs with very little code, and CodeIgniter Shield adds token-based authentication.
Does CodeIgniter have an ORM?
Not a full one. It uses the Query Builder and Entities for database work. You can add an outside ORM like Doctrine if your project needs it.
Is CodeIgniter secure?
Yes, when used correctly. It includes CSRF protection, input validation, output escaping, and Content Security Policy support. Keep CodeIgniter and PHP updated, and keep only the public/ folder web-accessible.
Can I use CodeIgniter with React or Vue?
Absolutely. Many teams use CodeIgniter as a JSON API backend for React, Vue, Angular, or mobile apps.
Jignesh Patel
Olson Fernandes