agyanadda@gmail.com

CodeIgniter 4 Spark Commands

CodeIgniter 4 Basics 1 min read Updated Dec 3, 2026 Topic 5 of 30

Spark is CodeIgniter 4's command-line tool. Run it from the project folder with php spark <command>.

Everyday commands

  • php spark list — all commands
  • php spark serve — development server
  • php spark routes — every route and its controller
  • php spark env — show the current environment

Generators

  • make:controller Blog (add --restful for a REST controller)
  • make:model BlogModel
  • make:migration CreateBlogTable
  • make:seeder BlogSeeder
  • make:filter AuthFilter
  • make:entity Blog
  • make:command SendReport — your own spark command
  • make:scaffold Blog — controller, model, migration, seeder together

Database

  • migrate, migrate:rollback, migrate:status
  • db:seed BlogSeeder
  • db:table posts — show a table's rows and fields

Other

  • cache:clear — clear the cache
  • key:generate — set the encryption key in .env

Add --help after any command to see its options.

Example

Example — Generate files with spark Bash
# See every route
php spark routes

# Create a model with matching files
php spark make:model PostModel
# File created: APPPATH/Models/PostModel.php

# Controller, model, migration and seeder in one go
php spark make:scaffold Post

# Run migrations and check their status
php spark migrate
php spark migrate:status

# Clear the cache
php spark cache:clear

Each make: command creates a ready-to-edit file in the right app folder with the correct namespace.

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which command lists all routes?

Exercise 2 True / False

php spark make:scaffold creates a controller, model, migration and seeder.

Exercise 3 Fill in the Blank

Run php spark ___:clear to empty the cache.

Frequently Asked Questions

Yes. Run php spark make:command SendReport, set $group, $name (for example report:send) and $description, and put the logic in run(). Then run php spark report:send. This is useful for cron jobs.