Catalog / CodeIgniter 4 Cheatsheet
CodeIgniter 4 Cheatsheet
A comprehensive cheat sheet for CodeIgniter 4, covering essential concepts, configurations, and code snippets to accelerate development.
Core Concepts & Configuration
MVC Structure
Model: Represents data and business logic. |
View: Handles the presentation of data to the user (HTML, etc.). |
Controller: Manages requests, interacts with models, and loads views. |
Directory Structure: |
|
|
|
|
Configuration (app/Config/App.php)
|
The base URL of your application (e.g., |
|
The name of your index page (usually |
|
Encryption key for secure sessions and data. |
|
The default locale for your application (e.g., |
|
The session driver to use ( |
|
The timezone for your application (e.g., |
Controllers & Routing
Creating a Controller
Create a file in |
|
Access the controller via URL (e.g., |
Routing
|
Configuration file for defining routes. |
|
Defines a GET route. |
|
Defines a POST route. |
|
Creates RESTful resource routes for a controller named ‘Photos’. |
Route Parameters |
|
Auto Route (Improved) |
Set |
Request Object
Accessing the request object in a controller:
|
|
Models & Database
Creating a Model
Create a file in |
|
Database Configuration (app/Config/Database.php)
|
Default database connection settings. |
|
Database server hostname (e.g., |
|
Database username. |
|
Database password. |
|
Database name. |
|
Database driver (e.g., |
Database Queries
|
|
Views & Templating
Creating a View
Create a file in |
|
Loading Views in Controller
|
Templating with View Layouts
Create a layout file (e.g.,
|
Create a view that extends the layout (e.g.,
|
In Controller:
|