What is CodeIgniter 4's CLI-only routes?
Why Interviewers Ask This
Interviewers ask this to evaluate whether you have the depth of knowledge needed to mentor others and lead technical decisions. The expected answer goes beyond definitions into practical implications and real-world consequences.
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.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a CodeIgniter codebase.
Previous
What is CI4 vs Laravel performance comparison?
Next
What is CodeIgniter 4 environment-specific configuration?