Interacting with console applications
The console is the third application installed by default with the advanced template.
This app is configured to launch commands through a console access, and it has the same application structure of those already seen in the previous chapters. Therefore, in this section, we require a console access to the host.
Compared to the web and API applications used until now, there are some differences.
The public
properties of a controller, in fact, are visible from the command line as option
. It is required to extend the option()
method of the controller to make those properties available. Also, based on specific action, action parameters are passed as arguments of the command line.
Finally, a console controller action can return an exit code, a number where 0 indicates that everything is OK, a best practice for console application development.
Here is a typical usage of the console application starting from a shell:
yii <route> [--option1=value1 --option2...