These are my personal study notes from learning and working with CodeIgniter 4. I use this repository to keep the core ideas, patterns, and PHP examples I want to revisit in one place.
The notes begin with a small working app and build toward routing, controllers, views, databases, validation, security, APIs, testing, and deployment. Each chapter explains the purpose of the feature, shows practical PHP examples, and points to the current official documentation for version-specific details.
This is a focused set of notes for building and maintaining CodeIgniter 4 applications. It covers the framework's request flow, MVC structure, Spark commands, configuration, data access, and the checks needed before a production release.
The examples use PHP and Composer. CodeIgniter and PHP requirements can change, so check the official requirements page when setting up a new project.
-
Installation and the first route
Set up PHP and Composer, create a CodeIgniter 4 app starter, run Spark, and return a first response. -
Project structure and configuration
Understand app, public, writable, environment settings, namespaces, autoloading, and configuration. -
Routing and route groups
Define explicit routes, HTTP verbs, route parameters, groups, filters, and named routes. -
Controllers, requests, and responses
Handle request data, return views or responses, use redirects, and separate HTTP work from domain logic. -
Views, layouts, and helpers
Build reusable view layouts, pass safe data, escape output, use helpers, and handle form values. -
Databases, Query Builder, and transactions
Configure database connections, compose safe queries, bind values, and protect multi-step changes. -
Models and CRUD
Use CodeIgniter models, allowed fields, validation, pagination, and clear data access methods. -
Migrations and seeders
Version database schema changes, seed repeatable data, and run or roll back migrations. -
Validation and form errors
Validate server input with strict rules, return field errors, preserve safe form values, and handle JSON data. -
Sessions, cookies, and flash data
Manage session state, use flash messages, configure cookies, and understand lifecycle and security limits. -
Filters, security, and file uploads
Apply route filters, CSRF protection, output escaping, secure uploads, and access checks. -
Building REST APIs
Design resource routes, validate JSON, return consistent status codes, and format API responses. -
Services, events, and Spark commands
Use shared services, register events, create CLI commands, and keep application bootstrapping understandable. -
Errors, logging, and caching
Configure environment-safe errors, record useful logs, and cache work that is safe to reuse. -
Testing controllers and models
Write focused unit and feature tests, use test responses, isolate data, and run the test suite. -
Deployment and production checklist
Configure production settings, document server requirements, run Composer production installs, and verify releases.
- All code samples collects the complete examples from the chapters.
- Complete questions and answers gathers review questions and clear answers.
Read in order for a guided study path, or use the chapter links to revisit one topic. Try each example in a local app, inspect the request and response, and test changes with your own data. Keep credentials out of source control and use environment-specific settings for local and production systems.
- CodeIgniter 4 user guide
- CodeIgniter 4 installation
- CodeIgniter 4 requirements
- CodeIgniter 4 source repository
These notes are available under the MIT License.
- Portfolio: https://www.ashishranjan.net
- GitHub: https://github.com/a2rp
- CodePen: https://codepen.io/ash1198
- LinkedIn: https://www.linkedin.com/in/aashishranjan
- Facebook: https://www.facebook.com/theash.ashish/
- YouTube: https://www.youtube.com/@ashishranjan-ashz?sub_confirmation=1
- Email: mailto:ash.ranjan09@gmail.com
- Support: https://a2rp-donation-page.netlify.app/
- Buy Me a Coffee: https://buymeacoffee.com/ashishranjan
- Patreon: https://www.patreon.com/ashishranjan