What is CodeIgniter 4's CLI-only routes?
Answer
CodeIgniter 4 supports routes that are only accessible via the command-line interface, not via HTTP requests. Define CLI-only routes: $routes->cli("migrate", "MigrateController::index"). These routes can only be called with php index.php migrate from the command line. Detect CLI environment in controllers: if (is_cli()) { /* CLI-specific logic */ }. CI4 also uses the CLI class for output: CLI::write("Done!", "green"), CLI::error("Failed!"), CLI::input("Enter name: "). CLI routes and controllers are useful for maintenance scripts, imports, and administrative tasks that should not be exposed via HTTP. For more structured CLI work, use Spark Commands instead — they provide argument parsing, option handling, and help text generation automatically. CLI routes are a simpler alternative for basic scripts.
Previous
What is CI4 vs Laravel performance comparison?
Next
What is CodeIgniter 4 environment-specific configuration?