From 64175feae2323b9b74e79dfe8823c43f32c2d043 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Thu, 16 Oct 2014 20:07:18 +0200 Subject: [PATCH] Update tutorial-console.md --- docs/guide/tutorial-console.md | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/guide/tutorial-console.md b/docs/guide/tutorial-console.md index c571448..86c521b 100644 --- a/docs/guide/tutorial-console.md +++ b/docs/guide/tutorial-console.md @@ -6,6 +6,7 @@ Console applications Yii has full featured support for console applications, whose structure is very similar to a Yii web application. A console application consists of one or more [[yii\console\Controller]] classes, which are often referred to as "commands" in the console environment. Each controller can also have one or more actions, just like web controllers. + Usage ----- @@ -23,13 +24,18 @@ be called from command line like so: yii migrate/create --migrationTable=my_migration ``` -In the above `yii` is the console application entry script described below. +In the above `yii` is the console application entry script which is described below. + +> **Note**: When using `*` in console don't forget to quote it as `"*"` in order to avoid executing it as a shell +> glob that will be replaced by all file names of the current directory. + Entry script ------------ -The console application entry script is equivalent to the `index.php` bootstrap file used for the web application. The console entry script is typically called `yii`, and located in your application's root directory. The contents of the console application entry script contains -code like the following: +The console application entry script is equivalent to the `index.php` bootstrap file used for the web application. +The console entry script is typically called `yii`, and located in your application's root directory. +It contains code like the following: ```php #!/usr/bin/env php @@ -52,12 +58,12 @@ $config = require(__DIR__ . '/config/console.php'); $application = new yii\console\Application($config); $exitCode = $application->run(); exit($exitCode); - ``` This script will be created as part of your application; you're free to edit it to suit your needs. The `YII_DEBUG` constant can be set `false` if you do not want to see a stack trace on error, and/or if you want to improve the overall performance. In both basic and advanced application -templates, the console application entry script has debugging enabled to provide a more developer-friendly environment. +templates, the console application entry script has debugging enabled by default to provide a more developer-friendly environment. + Configuration ------------- @@ -68,17 +74,15 @@ you should configure various [application components](structure-application-comp If your web application and the console application share a lot of configuration parameters and values, you may consider moving the common parts into a separate file, and including this file in both of the application configurations (web and console). You can see an example of this in the "advanced" application template. -Sometimes, you may want to run a console command using an application configuration that is different from the one -specified in the entry script. For example, you may want to use the `yii migrate` command to upgrade your -test databases, which are configured in each individual test suite. To do change the configuration dynamically, simply specify a custom application configuration -file via the `appconfig` option when executing the command: - -``` -yii --appconfig=path/to/config.php ... -``` - -> **Note**: When using `*` in console don't forget to quote it as `"*"` in order to avoid executing it as a shell -> command. +> Tipp: Sometimes, you may want to run a console command using an application configuration that is different +> from the one specified in the entry script. For example, you may want to use the `yii migrate` command to +> upgrade your test databases, which are configured in each individual test suite. To do change the configuration +> dynamically, simply specify a custom application configuration +> file via the `appconfig` option when executing the command: +> +> ``` +> yii --appconfig=path/to/config.php ... +> ``` Creating your own console commands