Commit f22c5212 by Alexander Makarov

A bit more docs on console applications

parent 951da01c
......@@ -7,7 +7,7 @@ consists of one or more [[\yii\console\Controller]] (often referred to as comman
Usage
-----
User executes controller action using the following syntax:
You can execute controller action using the following syntax:
```
yii <route> [--param1=value1 --param2 ...]
......@@ -20,13 +20,54 @@ line like the following:
yii migreate/create --migrationTable=my_migration
```
In the above `yii` is console application entry script described below.
Entry script
------------
Console application entry script is typically called `yii`, located in your application root directory and contains
code like the following:
```php
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
defined('YII_DEBUG') or define('YII_DEBUG', true);
// fcgi doesn't have STDIN defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
$config = require(__DIR__ . '/config/console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
```
This script is a part of your application so you're free to adjust it. There `YII_DEBUG` can be turned off if you do
not want to see stacktrace on error and want to improve overall performance. In both basic and advanced application
templates it is enabled to provide more developer-friendly environment.
Configuration
-------------
As can be seen in the code above, console application uses its own config files named `console.php` so you need to
configure database connection and the rest of the components you're going to use there in that file. If web and console
application configs have a lot in common it's a good idea to move matching parts into their own config files as it was
done in advanced application template.
Creating your own console commands
----------------------------------
......@@ -36,4 +77,7 @@ Creating your own console commands
### Parameters
### Return codes
\ No newline at end of file
### Return codes
Using return codes is the best practice of console application development. If command returns `0` it means everything
is OK. If it is a number more than zero, we have an error and integer returned is the error code.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment