This repository provides guides to CodeIgniter 4, including learning topics, steps, and examples.
| Topic | Learning Files |
|---|---|
| Routes | Create route at Routes.php |
| Database Configuration | Set up your database connection in Database.php or copy the env file, rename it to .env, and update the DATABASE section. |
| CRUD | Sample CRUD operations with Blogs:- Controller: List of method actions - Model: Available properties - Views: Form validation and session error display - Migration: Table and column setup - Seeder: Data seeding with Faker for development |
| Custom Form Validation | - Controller: Defines validation rules and handles form validation - Ruleset: Custom validation rules for product attributes - Config: Registers the new ruleset |
| Session Storage | - Config: Session configuration settings - Controller: Examples of session handling, flashdata, and tempdata operations |
| Filters | - Config: Define filter aliases - Routes: Apply filters to route groups - AuthFilter: Custom authentication filter to check login status |
| Helpers | - Autoload.php: Load helpers automatically - BaseController.php: Load helpers in the base controller - customize_helper.php: Example helper functions (array flattening and date formatting) |
| File Upload | - Routes: Define routes for file upload functionality - View: HTML form for file upload - Controller: Handle file upload logic and validation |
| RestAPI | - Routes: Define RESTful routes for the API - Controller: Implement RESTful API methods (index, show, create, update, delete) for handling blog resources - Testing Endpoints: Use a tool like Postman:- GET /blogs: List all blogs - GET /blogs/{id}: Get a single blog - POST /blogs: Create a new blog - PUT /blogs/{id}: Update a blog - DELETE /blogs/{id}: Delete a blog |
| Page | Path |
|---|---|
| Error 404 | error_404.php |
| Production Error | production.php |
| Command | Description |
|---|---|
php spark serve |
Start the local development server. |
php spark make:controller Name |
Create a new controller named Name. |
php spark make:model Name |
Create a new model named Name. |
php spark make:migration Name |
Create a new migration file named Name. |
php spark migrate |
Run all new migrations. |
php spark migrate:rollback |
Rollback the last migration operation. |
php spark db:seed NameSeeder |
Run the database seeder named NameSeeder. |
php spark make:seeder Name |
Create a new database seeder named Name. |
php spark make:filter Name |
Create a new filter named Name. |
php spark make:entity Name |
Create a new entity named Name. |
php spark make:command Name |
Create a new custom command named Name. |
php spark make:scaffold Name |
Create a scaffold (controller, model, views) named Name. |
php spark make:cell Name |
Create a new cell view named Name. |
php spark env |
Display the current environment settings. |
php spark cache:clear |
Clear the application cache. |
php spark clear-cache |
Another command to clear the application cache. |
php spark routes |
Display the list of all registered routes. |
php spark help |
Display help information for spark commands. |
php spark --list |
List all available spark commands. |
composer require --dev squizlabs/php_codesniffer
composer require --dev codeigniter/coding-standardvendor/bin/php-cs-fixer fix --verboseTo run phpcbf on a specific file, provide the path to the file:
vendor/bin/phpcbf app/Controllers/Home.phpTarget Specific Directories or Files
vendor/bin/phpcbf app public tests systemFor details:
vendor/bin/phpcbf --help