Configuration and usage
The basic structure of Yii2 console applications is very similar to the structure used in web applications. In Yii2, console commands that extend from yii\console\Controller
are nearly identical to yii\web\Controller
.
Entry script
Before moving on to the configuration files themselves, let's take a look at the console entry script, which is part of the file called yii
. This entry script serves as the bootstrapper for all our console commands, and in general, they can be run by calling this:
$ ./yii
This command will output all the currently available commands for the system. Like the web/index.php
entry script, though, it isn't aware of its environment yet. We can change this by replacing yii
with the following code block:
#!/usr/bin/env php <?php /** * Yii console bootstrap file. */ // Define our application_env variable as provided by nginx/apache if (!defined('APPLICATION_ENV')) { if (getenv('APPLICATION_ENV') != false) ...