PHP 클래스 yii\console\Application
Application extends from
Application by providing functionalities that are
specific to console requests. In particular, it deals with console requests
through a command-based approach:
- A console application consists of one or several possible user commands;
- Each user command is implemented as a class extending
Controller;
- User specifies which command to run on the command line;
- The command processes the user request with the specified parameters.
The command classes should be under the namespace specified by [[controllerNamespace]].
Their naming should follow the same naming convention as controllers. For example, the
help command
is implemented using the
HelpController class.
To run the console application, enter the following on the command line:
~~~
yii
[--param1=value1 --param2 ...]
~~~
where refers to a controller route in the form of ModuleID/ControllerID/ActionID
(e.g. sitemap/create), and param1, param2 refers to a set of named parameters that
will be used to initialize the controller action (e.g. --since=0 specifies a since parameter
whose value is 0 and a corresponding $since parameter is passed to the action method).
A help command is provided by default, which lists available commands and shows their usage.
To use this command, simply type:
~~~
yii help
~~~
파일 보기
프로젝트 열기: yiisoft/yii2
1 사용 예제들
공개 프로퍼티들
프로퍼티 |
타입 |
설명 |
|
$controller |
|
the currently active controller instance |
|
$defaultRoute |
|
the default route of this application. Defaults to 'help',
meaning the help command. |
|
$enableCoreCommands |
|
whether to enable the commands provided by the core framework.
Defaults to true. |
|
공개 메소드들
보호된 메소드들
메소드 상세
Returns the configuration of the built-in commands.
Returns the error handler component.
public getErrorHandler ( ) : yii\console\ErrorHandler |
리턴 |
yii\console\ErrorHandler |
the error handler application component. |
Returns the request component.
public getRequest ( ) : yii\console\Request |
리턴 |
yii\console\Request |
the request component. |
Returns the response component.
public getResponse ( ) : Response |
리턴 |
Response |
the response component. |
Handles the specified request.
public handleRequest ( yii\console\Request $request ) : Response |
$request |
yii\console\Request |
the request to be handled |
리턴 |
Response |
the resulting response |
Initialize the application.
This method will check if the command line option [[OPTION_APPCONFIG]] is specified.
If so, the corresponding file will be loaded as the application configuration.
Otherwise, the configuration provided as the parameter will be returned back.
protected loadConfig ( array $config ) : array |
$config |
array |
the configuration provided in the constructor. |
리턴 |
array |
the actual configuration to be used by the application. |
This method parses the specified route and creates the corresponding child module(s), controller and action
instances. It then calls [[Controller::runAction()]] to run the action with the given parameters.
If the route is empty, the method will use [[defaultRoute]].
For example, to run public function actionTest($a, $b) assuming that the controller has options the following
code should be used:
php
\Yii::$app->runAction('controller/test', ['option' => 'value', $a, $b]);
public runAction ( string $route, array $params = [] ) : integer | Response |
$route |
string |
the route that specifies the action. |
$params |
array |
the parameters to be passed to the action |
리턴 |
integer | Response |
the result of the action. This can be either an exit code or Response object.
Exit code 0 means normal, and other values mean abnormal. Exit code of `null` is treaded as `0` as well. |
프로퍼티 상세
the currently active controller instance
the default route of this application. Defaults to 'help',
meaning the help command.
$enableCoreCommands 공개적으로 프로퍼티
whether to enable the commands provided by the core framework.
Defaults to true.
public $enableCoreCommands |