# Application

> Application represents a console application.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [console](/docs/api/yii/console/index.md) › Application

| class | `yii\console\Application` |
| --- | --- |
| Extends | [`yii\base\Application`](/docs/api/yii/base/application/index.md) » [`yii\base\Module`](/docs/api/yii/base/module/index.md) » [`yii\di\ServiceLocator`](/docs/api/yii/di/servicelocator/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/console/Application.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/console/Application.php#L62) |

Application represents a console application.

Application extends from [`Application`](/docs/api/yii/base/application/index.md) 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`](/docs/api/yii/console/controller/index.md);
- 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`](/docs/api/yii/base/application/index.md#property-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 <route> [--param1=value1 --param2 ...]
```

where `<route>` 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
```

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-actionMap"></span>[`$actionMap`](/docs/api/yii/base/module/index.md#property-actionMap) | `array<string, class-string\|array<string, mixed>>` | Mapping from action IDs to standalone [`Action`](/docs/api/yii/base/action/index.md) class configurations. Default: `[]`. Available since 22.0. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-actionNamespace"></span>[`$actionNamespace`](/docs/api/yii/base/module/index.md#property-actionNamespace) | `string\|null` | The namespace where standalone [`Action`](/docs/api/yii/base/action/index.md) subclasses are located for convention-based discovery, parallel to [`$controllerNamespace`](/docs/api/yii/base/module/index.md#property-controllerNamespace) for controllers. Default: `null`. Available since 22.0. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-aliases"></span>[`$aliases`](/docs/api/yii/base/module/index.md#property-aliases) write-only | `array` | List of path aliases to be defined. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-assetManager"></span>[`$assetManager`](/docs/api/yii/base/application/index.md#property-assetManager) read-only | [`yii\web\AssetManager`](/docs/api/yii/web/assetmanager/index.md) | The asset manager application component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-authManager"></span>[`$authManager`](/docs/api/yii/base/application/index.md#property-authManager) read-only | [`yii\rbac\ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md)`\|null` | The auth manager application component or null if it's not configured. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-basePath"></span>[`$basePath`](/docs/api/yii/base/application/index.md#property-basePath) | `string` | The root directory of the application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-bootstrap"></span>[`$bootstrap`](/docs/api/yii/base/application/index.md#property-bootstrap) | `array` | List of components that should be run during the application [bootstrapping process](/docs/api/yii/base/application/index.md#method-bootstrap). Default: `[]`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-cache"></span>[`$cache`](/docs/api/yii/base/application/index.md#property-cache) read-only | [`yii\caching\CacheInterface`](/docs/api/yii/caching/cacheinterface/index.md)`\|null` | The cache application component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-charset"></span>[`$charset`](/docs/api/yii/base/application/index.md#property-charset) | `string` | The charset currently used for the application. Default: `'UTF-8'`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-components"></span>[`$components`](/docs/api/yii/di/servicelocator/index.md#property-components) | `array` | The list of the component definitions or the loaded component instances (ID => definition or instance). | [`yii\di\ServiceLocator`](/docs/api/yii/di/servicelocator/index.md) |
| <span id="property-container"></span>[`$container`](/docs/api/yii/base/application/index.md#property-container) write-only | `array` | Values given in terms of name-value pairs. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-controller"></span>`$controller` | [`Controller`](/docs/api/yii/console/controller/index.md)`\|null` | The currently active controller instance Default: `null`. | `Application` |
| <span id="property-controllerMap"></span>[`$controllerMap`](/docs/api/yii/base/module/index.md#property-controllerMap) | `array` | Mapping from controller ID to controller configurations. Default: `[]`. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-controllerNamespace"></span>[`$controllerNamespace`](/docs/api/yii/base/application/index.md#property-controllerNamespace) | `string` | The namespace that controller classes are located in. Default: `'app\controllers'`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-controllerPath"></span>[`$controllerPath`](/docs/api/yii/base/module/index.md#property-controllerPath) | `string` | The directory that contains the controller classes. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-db"></span>[`$db`](/docs/api/yii/base/application/index.md#property-db) read-only | [`yii\db\Connection`](/docs/api/yii/db/connection/index.md) | The database connection. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| [`$defaultRoute`](#property-defaultRoute) | `string` | The default route of this application. Default: `'help'`. | `Application` |
| [`$enableCoreCommands`](#property-enableCoreCommands) | `bool` | Whether to enable the commands provided by the core framework. Default: `true`. | `Application` |
| <span id="property-errorHandler"></span>`$errorHandler` read-only | [`ErrorHandler`](/docs/api/yii/console/errorhandler/index.md) | The error handler application component. | `Application` |
| <span id="property-extensions"></span>[`$extensions`](/docs/api/yii/base/application/index.md#property-extensions) | `array\|null` | List of installed Yii extensions. Default: `null`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-formatter"></span>[`$formatter`](/docs/api/yii/base/application/index.md#property-formatter) read-only | [`yii\i18n\Formatter`](/docs/api/yii/i18n/formatter/index.md) | The formatter application component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-i18n"></span>[`$i18n`](/docs/api/yii/base/application/index.md#property-i18n) read-only | [`yii\i18n\I18N`](/docs/api/yii/i18n/i18n/index.md) | The internationalization application component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-id"></span>[`$id`](/docs/api/yii/base/module/index.md#property-id) | `string` | An ID that uniquely identifies this module among other modules which have the same [parent](/docs/api/yii/base/module/index.md#property-module). Default: `null`. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-language"></span>[`$language`](/docs/api/yii/base/application/index.md#property-language) | `string` | The language that is meant to be used for end users. Default: `'en-US'`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-layout"></span>[`$layout`](/docs/api/yii/base/application/index.md#property-layout) | `string\|bool` | The layout that should be applied for views in this application. Default: `'main'`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-layoutPath"></span>[`$layoutPath`](/docs/api/yii/base/module/index.md#property-layoutPath) | `string` | The root directory of layout files. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-loadedModules"></span>[`$loadedModules`](/docs/api/yii/base/application/index.md#property-loadedModules) | `array` | List of loaded modules indexed by their class names. Default: `[]`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-log"></span>[`$log`](/docs/api/yii/base/application/index.md#property-log) read-only | [`yii\log\Dispatcher`](/docs/api/yii/log/dispatcher/index.md) | The log dispatcher application component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-mailer"></span>[`$mailer`](/docs/api/yii/base/application/index.md#property-mailer) read-only | [`yii\mail\MailerInterface`](/docs/api/yii/mail/mailerinterface/index.md) | The mailer application component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-module"></span>[`$module`](/docs/api/yii/base/module/index.md#property-module) | [`yii\base\Module`](/docs/api/yii/base/module/index.md)`\|null` | The parent module of this module. `null` if this module does not have a parent. Default: `null`. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-modules"></span>[`$modules`](/docs/api/yii/base/module/index.md#property-modules) | `array` | The modules (indexed by their IDs). | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-name"></span>[`$name`](/docs/api/yii/base/application/index.md#property-name) | `string` | The application name. Default: `'My Application'`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-params"></span>[`$params`](/docs/api/yii/base/module/index.md#property-params) | `array` | Custom module parameters (name => value). Default: `[]`. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-request"></span>`$request` read-only | [`Request`](/docs/api/yii/console/request/index.md) | The request component. | `Application` |
| <span id="property-requestedAction"></span>[`$requestedAction`](/docs/api/yii/base/application/index.md#property-requestedAction) | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<`[`yii\base\Controller`](/docs/api/yii/base/controller/index.md)`>\|null` | The requested Action. Default: `null`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-requestedParams"></span>[`$requestedParams`](/docs/api/yii/base/application/index.md#property-requestedParams) | `array\|null` | The parameters supplied to the requested action. Default: `null`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-requestedRoute"></span>[`$requestedRoute`](/docs/api/yii/base/application/index.md#property-requestedRoute) | `string` | The requested route Default: `null`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-response"></span>`$response` read-only | [`Response`](/docs/api/yii/console/response/index.md) | The response component. | `Application` |
| <span id="property-runtimePath"></span>[`$runtimePath`](/docs/api/yii/base/application/index.md#property-runtimePath) | `string` | The directory that stores runtime files. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-security"></span>[`$security`](/docs/api/yii/base/application/index.md#property-security) read-only | [`yii\base\Security`](/docs/api/yii/base/security/index.md) | The security application component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-sourceLanguage"></span>[`$sourceLanguage`](/docs/api/yii/base/application/index.md#property-sourceLanguage) | `string` | The language that the application is written in. Default: `'en-US'`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-state"></span>[`$state`](/docs/api/yii/base/application/index.md#property-state) | `int` | The current application state during a request handling life cycle. Default: `null`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-timeZone"></span>[`$timeZone`](/docs/api/yii/base/application/index.md#property-timeZone) | `string` | The time zone used by this application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-uniqueId"></span>[`$uniqueId`](/docs/api/yii/base/application/index.md#property-uniqueId) read-only | `string` | The unique ID of the module. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-urlManager"></span>[`$urlManager`](/docs/api/yii/base/application/index.md#property-urlManager) read-only | [`yii\web\UrlManager`](/docs/api/yii/web/urlmanager/index.md) | The URL manager for this application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-vendorPath"></span>[`$vendorPath`](/docs/api/yii/base/application/index.md#property-vendorPath) | `string` | The directory that stores vendor files. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-version"></span>[`$version`](/docs/api/yii/base/module/index.md#property-version) | `string\|callable\|null` | The version of this module. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-view"></span>[`$view`](/docs/api/yii/base/application/index.md#property-view) read-only | [`yii\base\View`](/docs/api/yii/base/view/index.md)`\|`[`yii\web\View`](/docs/api/yii/web/view/index.md) | The view application component that is used to render various view files. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/api/yii/base/module/index.md#property-viewPath) | `string` | The root directory of view files. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Constructor. | `Application` |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/di/servicelocator/index.md#method-__get) | Getter magic method. | [`yii\di\ServiceLocator`](/docs/api/yii/di/servicelocator/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/di/servicelocator/index.md#method-__isset) | Checks if a property value is null. | [`yii\di\ServiceLocator`](/docs/api/yii/di/servicelocator/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-afterAction"></span>[`afterAction()`](/docs/api/yii/base/module/index.md#method-afterAction) | This method is invoked right after an action within this module is executed. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-beforeAction"></span>[`beforeAction()`](/docs/api/yii/base/module/index.md#method-beforeAction) | This method is invoked right before an action within this module is executed. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-clear"></span>[`clear()`](/docs/api/yii/di/servicelocator/index.md#method-clear) | Removes the component from the locator. | [`yii\di\ServiceLocator`](/docs/api/yii/di/servicelocator/index.md) |
| [`coreCommands()`](#method-coreCommands) | Returns the configuration of the built-in commands. | `Application` |
| [`coreComponents()`](#method-coreComponents) | Returns the configuration of core application components. | `Application` |
| <span id="method-createController"></span>[`createController()`](/docs/api/yii/base/module/index.md#method-createController) | Creates a controller instance based on the given route. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-createControllerByID"></span>[`createControllerByID()`](/docs/api/yii/base/module/index.md#method-createControllerByID) | Creates a controller based on the given controller ID. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-end"></span>[`end()`](/docs/api/yii/base/application/index.md#method-end) | Terminates the application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-get"></span>[`get()`](/docs/api/yii/base/module/index.md#method-get) | Returns the component instance with the specified ID. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-getAssetManager"></span>[`getAssetManager()`](/docs/api/yii/base/application/index.md#method-getAssetManager) | Returns the asset manager. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getAuthManager"></span>[`getAuthManager()`](/docs/api/yii/base/application/index.md#method-getAuthManager) | Returns the auth manager for this application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getBasePath"></span>[`getBasePath()`](/docs/api/yii/base/module/index.md#method-getBasePath) | Returns the root directory of the module. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getCache"></span>[`getCache()`](/docs/api/yii/base/application/index.md#method-getCache) | Returns the cache component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getComponents"></span>[`getComponents()`](/docs/api/yii/di/servicelocator/index.md#method-getComponents) | Returns the list of the component definitions or the loaded component instances. | [`yii\di\ServiceLocator`](/docs/api/yii/di/servicelocator/index.md) |
| <span id="method-getControllerPath"></span>[`getControllerPath()`](/docs/api/yii/base/module/index.md#method-getControllerPath) | Returns the directory that contains the controller classes according to [`$controllerNamespace`](/docs/api/yii/base/module/index.md#property-controllerNamespace). | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-getDb"></span>[`getDb()`](/docs/api/yii/base/application/index.md#method-getDb) | Returns the database connection component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| [`getErrorHandler()`](#method-getErrorHandler) | Returns the error handler component. | `Application` |
| <span id="method-getFormatter"></span>[`getFormatter()`](/docs/api/yii/base/application/index.md#method-getFormatter) | Returns the formatter component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getI18n"></span>[`getI18n()`](/docs/api/yii/base/application/index.md#method-getI18n) | Returns the internationalization (i18n) component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getInstance"></span>[`getInstance()`](/docs/api/yii/base/module/index.md#method-getInstance) static | Returns the currently requested instance of this module class. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-getLayoutPath"></span>[`getLayoutPath()`](/docs/api/yii/base/module/index.md#method-getLayoutPath) | Returns the directory that contains layout view files for this module. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-getLog"></span>[`getLog()`](/docs/api/yii/base/application/index.md#method-getLog) | Returns the log dispatcher component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getMailer"></span>[`getMailer()`](/docs/api/yii/base/application/index.md#method-getMailer) | Returns the mailer component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getModule"></span>[`getModule()`](/docs/api/yii/base/module/index.md#method-getModule) | Retrieves the child module of the specified ID. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-getModules"></span>[`getModules()`](/docs/api/yii/base/module/index.md#method-getModules) | Returns the sub-modules in this module. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| [`getRequest()`](#method-getRequest) | Returns the request component. | `Application` |
| [`getResponse()`](#method-getResponse) | Returns the response component. | `Application` |
| <span id="method-getRuntimePath"></span>[`getRuntimePath()`](/docs/api/yii/base/application/index.md#method-getRuntimePath) | Returns the directory that stores runtime files. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getSecurity"></span>[`getSecurity()`](/docs/api/yii/base/application/index.md#method-getSecurity) | Returns the security component. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getTimeZone"></span>[`getTimeZone()`](/docs/api/yii/base/application/index.md#method-getTimeZone) | Returns the time zone used by this application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getUniqueId"></span>[`getUniqueId()`](/docs/api/yii/base/application/index.md#method-getUniqueId) | Returns an ID that uniquely identifies this module among all modules within the current application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getUrlManager"></span>[`getUrlManager()`](/docs/api/yii/base/application/index.md#method-getUrlManager) | Returns the URL manager for this application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getVendorPath"></span>[`getVendorPath()`](/docs/api/yii/base/application/index.md#method-getVendorPath) | Returns the directory that stores vendor files. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getVersion"></span>[`getVersion()`](/docs/api/yii/base/module/index.md#method-getVersion) | Returns current module version. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-getView"></span>[`getView()`](/docs/api/yii/base/application/index.md#method-getView) | Returns the view object. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-getViewPath"></span>[`getViewPath()`](/docs/api/yii/base/module/index.md#method-getViewPath) | Returns the directory that contains the view files for this module. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| [`handleRequest()`](#method-handleRequest) | Handles the specified request. | `Application` |
| <span id="method-has"></span>[`has()`](/docs/api/yii/base/module/index.md#method-has) | Returns a value indicating whether the locator has the specified component definition or has instantiated the component. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasModule"></span>[`hasModule()`](/docs/api/yii/base/module/index.md#method-hasModule) | Checks whether the child module of the specified ID exists. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initialize the application. | `Application` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-preInit"></span>[`preInit()`](/docs/api/yii/base/application/index.md#method-preInit) | Pre-initializes the application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-run"></span>[`run()`](/docs/api/yii/base/application/index.md#method-run) | Runs the application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| [`runAction()`](#method-runAction) | Runs a controller action specified by a route. | `Application` |
| <span id="method-set"></span>[`set()`](/docs/api/yii/di/servicelocator/index.md#method-set) | Registers a component definition with this locator. | [`yii\di\ServiceLocator`](/docs/api/yii/di/servicelocator/index.md) |
| <span id="method-setAliases"></span>[`setAliases()`](/docs/api/yii/base/module/index.md#method-setAliases) | Defines path aliases. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-setBasePath"></span>[`setBasePath()`](/docs/api/yii/base/application/index.md#method-setBasePath) | Sets the root directory of the application and the @app alias. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-setComponents"></span>[`setComponents()`](/docs/api/yii/di/servicelocator/index.md#method-setComponents) | Registers a set of component definitions in this locator. | [`yii\di\ServiceLocator`](/docs/api/yii/di/servicelocator/index.md) |
| <span id="method-setContainer"></span>[`setContainer()`](/docs/api/yii/base/application/index.md#method-setContainer) | Configures [`Yii::$container`](/docs/api/yii/baseyii/index.md#property-container) with the $config. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-setControllerPath"></span>[`setControllerPath()`](/docs/api/yii/base/module/index.md#method-setControllerPath) | Sets the directory that contains the controller classes. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-setInstance"></span>[`setInstance()`](/docs/api/yii/base/module/index.md#method-setInstance) static | Sets the currently requested instance of this module class. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-setLayoutPath"></span>[`setLayoutPath()`](/docs/api/yii/base/module/index.md#method-setLayoutPath) | Sets the directory that contains the layout files. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-setModule"></span>[`setModule()`](/docs/api/yii/base/module/index.md#method-setModule) | Adds a sub-module to this module. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-setModules"></span>[`setModules()`](/docs/api/yii/base/module/index.md#method-setModules) | Registers sub-modules in the current module. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-setRuntimePath"></span>[`setRuntimePath()`](/docs/api/yii/base/application/index.md#method-setRuntimePath) | Sets the directory that stores runtime files. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-setTimeZone"></span>[`setTimeZone()`](/docs/api/yii/base/application/index.md#method-setTimeZone) | Sets the time zone used by this application. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-setVendorPath"></span>[`setVendorPath()`](/docs/api/yii/base/application/index.md#method-setVendorPath) | Sets the directory that stores vendor files. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-setVersion"></span>[`setVersion()`](/docs/api/yii/base/module/index.md#method-setVersion) | Sets current module version. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-setViewPath"></span>[`setViewPath()`](/docs/api/yii/base/module/index.md#method-setViewPath) | Sets the directory that contains the view files. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-bootstrap"></span>[`bootstrap()`](/docs/api/yii/base/application/index.md#method-bootstrap) protected | Initializes extensions and executes bootstrap components. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-createStandaloneAction"></span>[`createStandaloneAction()`](/docs/api/yii/base/module/index.md#method-createStandaloneAction) protected | Resolves a route to a standalone [`Action`](/docs/api/yii/base/action/index.md) class through convention-based discovery under [`$actionNamespace`](/docs/api/yii/base/module/index.md#property-actionNamespace). | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-defaultVersion"></span>[`defaultVersion()`](/docs/api/yii/base/module/index.md#method-defaultVersion) protected | Returns default module version. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| [`loadConfig()`](#method-loadConfig) protected | Loads the configuration. | `Application` |
| <span id="method-registerErrorHandler"></span>[`registerErrorHandler()`](/docs/api/yii/base/application/index.md#method-registerErrorHandler) protected | Registers the errorHandler component as a PHP error handler. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="method-runMappedAction"></span>[`runMappedAction()`](/docs/api/yii/base/module/index.md#method-runMappedAction) protected | Runs a standalone action registered in [`$actionMap`](/docs/api/yii/base/module/index.md#property-actionMap). | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="method-runStandaloneAction"></span>[`runStandaloneAction()`](/docs/api/yii/base/module/index.md#method-runStandaloneAction) protected | Runs a standalone [`Action`](/docs/api/yii/base/action/index.md) instance through the standard module/action event lifecycle. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |

## Events

| Event | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="event-EVENT_BEFORE_REQUEST"></span>[`EVENT_BEFORE_REQUEST`](/docs/api/yii/base/application/index.md#event-EVENT_BEFORE_REQUEST) | [`yii\base\Event`](/docs/api/yii/base/event/index.md) | An event raised before the application starts to handle a request. Event name: `'beforeRequest'`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="event-EVENT_AFTER_REQUEST"></span>[`EVENT_AFTER_REQUEST`](/docs/api/yii/base/application/index.md#event-EVENT_AFTER_REQUEST) | [`yii\base\Event`](/docs/api/yii/base/event/index.md) | An event raised after the application successfully handles a request (before the response is sent out). Event name: `'afterRequest'`. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="event-EVENT_BEFORE_ACTION"></span>[`EVENT_BEFORE_ACTION`](/docs/api/yii/base/module/index.md#event-EVENT_BEFORE_ACTION) | [`yii\base\ActionEvent`](/docs/api/yii/base/actionevent/index.md) | An event raised before executing a controller action. Event name: `'beforeAction'`. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |
| <span id="event-EVENT_AFTER_ACTION"></span>[`EVENT_AFTER_ACTION`](/docs/api/yii/base/module/index.md#event-EVENT_AFTER_ACTION) | [`yii\base\ActionEvent`](/docs/api/yii/base/actionevent/index.md) | An event raised after executing a controller action. Event name: `'afterAction'`. | [`yii\base\Module`](/docs/api/yii/base/module/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-OPTION_APPCONFIG"></span>`OPTION_APPCONFIG` | `'appconfig'` | The option name for specifying the application configuration file path. | `Application` |
| <span id="const-STATE_BEGIN"></span>[`STATE_BEGIN`](/docs/api/yii/base/application/index.md#const-STATE_BEGIN) | `0` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application just started. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="const-STATE_INIT"></span>[`STATE_INIT`](/docs/api/yii/base/application/index.md#const-STATE_INIT) | `1` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application is initializing. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="const-STATE_BEFORE_REQUEST"></span>[`STATE_BEFORE_REQUEST`](/docs/api/yii/base/application/index.md#const-STATE_BEFORE_REQUEST) | `2` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application is triggering [`EVENT_BEFORE_REQUEST`](/docs/api/yii/base/application/index.md#event-EVENT_BEFORE_REQUEST). | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="const-STATE_HANDLING_REQUEST"></span>[`STATE_HANDLING_REQUEST`](/docs/api/yii/base/application/index.md#const-STATE_HANDLING_REQUEST) | `3` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application is handling the request. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="const-STATE_AFTER_REQUEST"></span>[`STATE_AFTER_REQUEST`](/docs/api/yii/base/application/index.md#const-STATE_AFTER_REQUEST) | `4` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application is triggering [`EVENT_AFTER_REQUEST`](/docs/api/yii/base/application/index.md#event-EVENT_AFTER_REQUEST). | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="const-STATE_SENDING_RESPONSE"></span>[`STATE_SENDING_RESPONSE`](/docs/api/yii/base/application/index.md#const-STATE_SENDING_RESPONSE) | `5` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application is about to send response. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |
| <span id="const-STATE_END"></span>[`STATE_END`](/docs/api/yii/base/application/index.md#const-STATE_END) | `6` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application has ended. | [`yii\base\Application`](/docs/api/yii/base/application/index.md) |

## Property details

### $defaultRoute <span id="property-defaultRoute"></span>

```php
public string $defaultRoute = 'help'
```

The default route of this application.

Defaults to 'help',
meaning the `help` command.

### $enableCoreCommands <span id="property-enableCoreCommands"></span>

```php
public bool $enableCoreCommands = true
```

Whether to enable the commands provided by the core framework.

Defaults to true.

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(mixed $config = [])
```

Constructor.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `mixed` | Name-value pairs that will be used to initialize the object properties. Note that the configuration must contain both [`$id`](/docs/api/yii/base/module/index.md#property-id) and [`$basePath`](/docs/api/yii/base/application/index.md#property-basePath). |

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if either [`$id`](/docs/api/yii/base/module/index.md#property-id) or [`$basePath`](/docs/api/yii/base/application/index.md#property-basePath) configuration is missing.

### coreCommands() <span id="method-coreCommands"></span>

```php
public function coreCommands(): array
```

Returns the configuration of the built-in commands.

**Returns**

`array`: The configuration of the built-in commands.

### coreComponents() <span id="method-coreComponents"></span>

```php
public function coreComponents(): array
```

Returns the configuration of core application components.

**Returns**

`array`

### getErrorHandler() <span id="method-getErrorHandler"></span>

```php
public function getErrorHandler(): yii\console\ErrorHandler
```

Returns the error handler component.

**Returns**

[`ErrorHandler`](/docs/api/yii/console/errorhandler/index.md): The error handler application component.

### getRequest() <span id="method-getRequest"></span>

```php
public function getRequest(): yii\console\Request
```

Returns the request component.

**Returns**

[`Request`](/docs/api/yii/console/request/index.md): The request component.

### getResponse() <span id="method-getResponse"></span>

```php
public function getResponse(): yii\console\Response
```

Returns the response component.

**Returns**

[`Response`](/docs/api/yii/console/response/index.md): The response component.

### handleRequest() <span id="method-handleRequest"></span>

```php
public function handleRequest(yii\console\Request $request): yii\console\Response
```

Handles the specified request.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | [`Request`](/docs/api/yii/console/request/index.md) | The request to be handled |

**Returns**

[`Response`](/docs/api/yii/console/response/index.md): The resulting response

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initialize the application.

**Returns**

`mixed`

### runAction() <span id="method-runAction"></span>

```php
public function runAction(string $route, array $params = []): int|yii\console\Response|null
```

Runs a controller action specified by a route.

This method parses the specified route and creates the corresponding child module(s), controller and action
instances. It then calls [`Controller::runAction()`](/docs/api/yii/console/controller/index.md#method-runAction) to run the action with the given parameters.
If the route is empty, the method will use [`$defaultRoute`](/docs/api/yii/console/application/index.md#property-defaultRoute).

For example, to run `public function actionTest($a, $b)` assuming that the controller has options the following
code should be used:

```
\Yii::$app->runAction('controller/test', ['option' => 'value', $a, $b]);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$route` | `string` | The route that specifies the action. |
| `$params` | `array` | The parameters to be passed to the action |

**Returns**

`int|`[`Response`](/docs/api/yii/console/response/index.md)`|null`: 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 treated as `0` as well.

**Throws**

- [`Exception`](/docs/api/yii/console/exception/index.md): if the route is invalid

### loadConfig() <span id="method-loadConfig"></span>

```php
protected function loadConfig(array $config): array
```

Loads the configuration.

This method will check if the command line option [`OPTION_APPCONFIG`](/docs/api/yii/console/application/index.md#const-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.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array` | The configuration provided in the constructor. |

**Returns**

`array`: The actual configuration to be used by the application.