# Application

> Application is the base class for all application classes.

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

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

2 subclasses:

- [`yii\console\Application`](/docs/api/yii/console/application/index.md)
- [`yii\web\Application`](/docs/api/yii/web/application/index.md)

Application is the base class for all application classes.

For more details and usage information on Application, see the [guide article on applications](/docs/guide/structure-applications/index.md).

## 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. | [`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. | [`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. | [`Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-assetManager"></span>`$assetManager` read-only | [`yii\web\AssetManager`](/docs/api/yii/web/assetmanager/index.md) | The asset manager application component. | `Application` |
| <span id="property-authManager"></span>`$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. | `Application` |
| <span id="property-basePath"></span>`$basePath` | `string` | The root directory of the application. | `Application` |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`Component`](/docs/api/yii/base/component/index.md) |
| [`$bootstrap`](#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: `[]`. | `Application` |
| [`$cache`](#property-cache) read-only | [`yii\caching\CacheInterface`](/docs/api/yii/caching/cacheinterface/index.md)`\|null` | The cache application component. | `Application` |
| <span id="property-charset"></span>`$charset` | `string` | The charset currently used for the application. Default: `'UTF-8'`. | `Application` |
| <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` write-only | `array` | Values given in terms of name-value pairs. | `Application` |
| <span id="property-controller"></span>`$controller` | [`Controller`](/docs/api/yii/base/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: `[]`. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`$controllerNamespace`](#property-controllerNamespace) | `string` | The namespace that controller classes are located in. Default: `'app\controllers'`. | `Application` |
| <span id="property-controllerPath"></span>[`$controllerPath`](/docs/api/yii/base/module/index.md#property-controllerPath) | `string` | The directory that contains the controller classes. | [`Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-db"></span>`$db` read-only | [`yii\db\Connection`](/docs/api/yii/db/connection/index.md) | The database connection. | `Application` |
| <span id="property-defaultRoute"></span>[`$defaultRoute`](/docs/api/yii/base/module/index.md#property-defaultRoute) | `string` | The default route of this module. Default: `'default'`. | [`Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-errorHandler"></span>`$errorHandler` read-only | [`yii\web\ErrorHandler`](/docs/api/yii/web/errorhandler/index.md)`\|`[`yii\console\ErrorHandler`](/docs/api/yii/console/errorhandler/index.md) | The error handler application component. | `Application` |
| [`$extensions`](#property-extensions) | `array\|null` | List of installed Yii extensions. Default: `null`. | `Application` |
| <span id="property-formatter"></span>`$formatter` read-only | [`yii\i18n\Formatter`](/docs/api/yii/i18n/formatter/index.md) | The formatter application component. | `Application` |
| <span id="property-i18n"></span>`$i18n` read-only | [`yii\i18n\I18N`](/docs/api/yii/i18n/i18n/index.md) | The internationalization application component. | `Application` |
| <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`. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`$language`](#property-language) | `string` | The language that is meant to be used for end users. Default: `'en-US'`. | `Application` |
| [`$layout`](#property-layout) | `string\|bool` | The layout that should be applied for views in this application. Default: `'main'`. | `Application` |
| <span id="property-layoutPath"></span>[`$layoutPath`](/docs/api/yii/base/module/index.md#property-layoutPath) | `string` | The root directory of layout files. | [`Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-loadedModules"></span>`$loadedModules` | `array` | List of loaded modules indexed by their class names. Default: `[]`. | `Application` |
| <span id="property-log"></span>`$log` read-only | [`yii\log\Dispatcher`](/docs/api/yii/log/dispatcher/index.md) | The log dispatcher application component. | `Application` |
| <span id="property-mailer"></span>`$mailer` read-only | [`yii\mail\MailerInterface`](/docs/api/yii/mail/mailerinterface/index.md) | The mailer application component. | `Application` |
| <span id="property-module"></span>[`$module`](/docs/api/yii/base/module/index.md#property-module) | [`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`. | [`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). | [`Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-name"></span>`$name` | `string` | The application name. Default: `'My Application'`. | `Application` |
| <span id="property-params"></span>[`$params`](/docs/api/yii/base/module/index.md#property-params) | `array` | Custom module parameters (name => value). Default: `[]`. | [`Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-request"></span>`$request` read-only | [`yii\web\Request`](/docs/api/yii/web/request/index.md)`\|`[`yii\console\Request`](/docs/api/yii/console/request/index.md) | The request component. | `Application` |
| [`$requestedAction`](#property-requestedAction) | [`Action`](/docs/api/yii/base/action/index.md)`<`[`Controller`](/docs/api/yii/base/controller/index.md)`>\|null` | The requested Action. Default: `null`. | `Application` |
| <span id="property-requestedParams"></span>`$requestedParams` | `array\|null` | The parameters supplied to the requested action. Default: `null`. | `Application` |
| <span id="property-requestedRoute"></span>`$requestedRoute` | `string` | The requested route Default: `null`. | `Application` |
| <span id="property-response"></span>`$response` read-only | [`yii\web\Response`](/docs/api/yii/web/response/index.md)`\|`[`yii\console\Response`](/docs/api/yii/console/response/index.md) | The response component. | `Application` |
| [`$runtimePath`](#property-runtimePath) | `string` | The directory that stores runtime files. | `Application` |
| <span id="property-security"></span>`$security` read-only | [`Security`](/docs/api/yii/base/security/index.md) | The security application component. | `Application` |
| [`$sourceLanguage`](#property-sourceLanguage) | `string` | The language that the application is written in. Default: `'en-US'`. | `Application` |
| [`$state`](#property-state) | `int` | The current application state during a request handling life cycle. Default: `null`. | `Application` |
| <span id="property-timeZone"></span>`$timeZone` | `string` | The time zone used by this application. | `Application` |
| <span id="property-uniqueId"></span>`$uniqueId` read-only | `string` | The unique ID of the module. | `Application` |
| <span id="property-urlManager"></span>`$urlManager` read-only | [`yii\web\UrlManager`](/docs/api/yii/web/urlmanager/index.md) | The URL manager for this application. | `Application` |
| [`$vendorPath`](#property-vendorPath) | `string` | The directory that stores vendor files. | `Application` |
| <span id="property-version"></span>[`$version`](/docs/api/yii/base/module/index.md#property-version) | `string\|callable\|null` | The version of this module. | [`Module`](/docs/api/yii/base/module/index.md) |
| <span id="property-view"></span>`$view` read-only | [`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. | `Application` |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/api/yii/base/module/index.md#property-viewPath) | `string` | The root directory of view files. | [`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. | [`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. | [`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. | [`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. | [`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. | [`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. | [`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. | [`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. | [`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. | [`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. | [`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. | [`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. | [`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) |
| [`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. | [`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. | [`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. | [`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. | [`Component`](/docs/api/yii/base/component/index.md) |
| [`end()`](#method-end) | Terminates the application. | `Application` |
| <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. | [`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. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`getAssetManager()`](#method-getAssetManager) | Returns the asset manager. | `Application` |
| [`getAuthManager()`](#method-getAuthManager) | Returns the auth manager for this application. | `Application` |
| <span id="method-getBasePath"></span>[`getBasePath()`](/docs/api/yii/base/module/index.md#method-getBasePath) | Returns the root directory of the module. | [`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. | [`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. | [`Component`](/docs/api/yii/base/component/index.md) |
| [`getCache()`](#method-getCache) | Returns the cache component. | `Application` |
| <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). | [`Module`](/docs/api/yii/base/module/index.md) |
| [`getDb()`](#method-getDb) | Returns the database connection component. | `Application` |
| [`getErrorHandler()`](#method-getErrorHandler) | Returns the error handler component. | `Application` |
| [`getFormatter()`](#method-getFormatter) | Returns the formatter component. | `Application` |
| [`getI18n()`](#method-getI18n) | Returns the internationalization (i18n) component. | `Application` |
| <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. | [`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. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`getLog()`](#method-getLog) | Returns the log dispatcher component. | `Application` |
| [`getMailer()`](#method-getMailer) | Returns the mailer component. | `Application` |
| <span id="method-getModule"></span>[`getModule()`](/docs/api/yii/base/module/index.md#method-getModule) | Retrieves the child module of the specified ID. | [`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. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`getRequest()`](#method-getRequest) | Returns the request component. | `Application` |
| [`getResponse()`](#method-getResponse) | Returns the response component. | `Application` |
| [`getRuntimePath()`](#method-getRuntimePath) | Returns the directory that stores runtime files. | `Application` |
| [`getSecurity()`](#method-getSecurity) | Returns the security component. | `Application` |
| [`getTimeZone()`](#method-getTimeZone) | Returns the time zone used by this application. | `Application` |
| [`getUniqueId()`](#method-getUniqueId) | Returns an ID that uniquely identifies this module among all modules within the current application. | `Application` |
| [`getUrlManager()`](#method-getUrlManager) | Returns the URL manager for this application. | `Application` |
| [`getVendorPath()`](#method-getVendorPath) | Returns the directory that stores vendor files. | `Application` |
| <span id="method-getVersion"></span>[`getVersion()`](/docs/api/yii/base/module/index.md#method-getVersion) | Returns current module version. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`getView()`](#method-getView) | Returns the view object. | `Application` |
| <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. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`handleRequest()`](#method-handleRequest) abstract | 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. | [`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. | [`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. | [`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. | [`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. | [`Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initializes the module. | `Application` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`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. | [`Component`](/docs/api/yii/base/component/index.md) |
| [`preInit()`](#method-preInit) | Pre-initializes the application. | `Application` |
| [`run()`](#method-run) | Runs the application. | `Application` |
| <span id="method-runAction"></span>[`runAction()`](/docs/api/yii/base/module/index.md#method-runAction) | Runs a controller action specified by a route. | [`Module`](/docs/api/yii/base/module/index.md) |
| <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. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`setBasePath()`](#method-setBasePath) | Sets the root directory of the application and the @app alias. | `Application` |
| <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) |
| [`setContainer()`](#method-setContainer) | Configures [`Yii::$container`](/docs/api/yii/baseyii/index.md#property-container) with the $config. | `Application` |
| <span id="method-setControllerPath"></span>[`setControllerPath()`](/docs/api/yii/base/module/index.md#method-setControllerPath) | Sets the directory that contains the controller classes. | [`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. | [`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. | [`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. | [`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. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`setRuntimePath()`](#method-setRuntimePath) | Sets the directory that stores runtime files. | `Application` |
| [`setTimeZone()`](#method-setTimeZone) | Sets the time zone used by this application. | `Application` |
| [`setVendorPath()`](#method-setVendorPath) | Sets the directory that stores vendor files. | `Application` |
| <span id="method-setVersion"></span>[`setVersion()`](/docs/api/yii/base/module/index.md#method-setVersion) | Sets current module version. | [`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. | [`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. | [`Component`](/docs/api/yii/base/component/index.md) |
| [`bootstrap()`](#method-bootstrap) protected | Initializes extensions and executes bootstrap components. | `Application` |
| <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). | [`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. | [`Module`](/docs/api/yii/base/module/index.md) |
| [`registerErrorHandler()`](#method-registerErrorHandler) protected | Registers the errorHandler component as a PHP error handler. | `Application` |
| <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). | [`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. | [`Module`](/docs/api/yii/base/module/index.md) |

## Events

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

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-STATE_BEGIN"></span>`STATE_BEGIN` | `0` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application just started. | `Application` |
| <span id="const-STATE_INIT"></span>`STATE_INIT` | `1` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application is initializing. | `Application` |
| <span id="const-STATE_BEFORE_REQUEST"></span>`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). | `Application` |
| <span id="const-STATE_HANDLING_REQUEST"></span>`STATE_HANDLING_REQUEST` | `3` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application is handling the request. | `Application` |
| <span id="const-STATE_AFTER_REQUEST"></span>`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). | `Application` |
| <span id="const-STATE_SENDING_RESPONSE"></span>`STATE_SENDING_RESPONSE` | `5` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application is about to send response. | `Application` |
| <span id="const-STATE_END"></span>`STATE_END` | `6` | Application state used by [`$state`](/docs/api/yii/base/application/index.md#property-state): application has ended. | `Application` |

## Property details

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

```php
public array $bootstrap = []
```

List of components that should be run during the application [bootstrapping process](/docs/api/yii/base/application/index.md#method-bootstrap).

Each component may be specified in one of the following formats:

- an application component ID as specified via [`$components`](/docs/api/yii/di/servicelocator/index.md#property-components).
- a module ID as specified via [`$modules`](/docs/api/yii/base/module/index.md#property-modules).
- a class name.
- a configuration array.
- a Closure

During the bootstrapping process, each component will be instantiated. If the component class
implements [`BootstrapInterface`](/docs/api/yii/base/bootstrapinterface/index.md), its [bootstrap()](/docs/api/yii/base/bootstrapinterface/index.md#method-bootstrap) method
will be also be called.

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

```php
public yii\caching\CacheInterface|null $cache
```

The cache application component.

Null if the
component is not enabled.

**Access**

Read-only (virtual property).

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

```php
public string $controllerNamespace = 'app\controllers'
```

The namespace that controller classes are located in.

This namespace will be used to load controller classes by prepending it to the controller class name.
The default namespace is `app\controllers`.

Please refer to the [guide about class autoloading](/docs/guide/concept-autoloading/index.md) for more details.

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

```php
public array|null $extensions = null
```

List of installed Yii extensions.

Each array element represents a single extension
with the following structure:

```
[
    'name' => 'extension name',
    'version' => 'version number',
    'bootstrap' => 'BootstrapClassName',  // optional, may also be a configuration array
    'alias' => [
        '@alias1' => 'to/path1',
        '@alias2' => 'to/path2',
    ],
]
```

The "bootstrap" class listed above will be instantiated during the application
[bootstrapping process](/docs/api/yii/base/application/index.md#method-bootstrap). If the class implements [`BootstrapInterface`](/docs/api/yii/base/bootstrapinterface/index.md),
its [bootstrap()](/docs/api/yii/base/bootstrapinterface/index.md#method-bootstrap) method will be also be called.

If not set explicitly in the application config, this property will be populated with the contents of
`@vendor/yiisoft/extensions.php`.

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

```php
public string $language = 'en-US'
```

The language that is meant to be used for end users.

It is recommended that you
use [IETF language tags](https://en.wikipedia.org/wiki/IETF_language_tag). For example, `en` stands
for English, while `en-US` stands for English (United States).

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

```php
public string|bool $layout = 'main'
```

The layout that should be applied for views in this application.

Defaults to 'main'.
If this is false, layout will be disabled.

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

```php
public yii\base\Action<yii\base\Controller>|null $requestedAction = null
```

The requested Action.

If null, it means the request cannot be resolved into an action.

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

```php
public string $runtimePath
```

The directory that stores runtime files.

Defaults to the "runtime"
subdirectory under [`$basePath`](/docs/api/yii/base/application/index.md#property-basePath).

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

```php
public string $sourceLanguage = 'en-US'
```

The language that the application is written in.

This mainly refers to
the language that the messages and view files are written in.

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

```php
public int $state = null
```

The current application state during a request handling life cycle.

This property is managed by the application. Do not modify this property.

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

```php
public string $vendorPath
```

The directory that stores vendor files.

Defaults to "vendor" directory under
[`$basePath`](/docs/api/yii/base/application/index.md#property-basePath).

## Method details

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

```php
public function __construct(array<array-key, mixed> $config = [])
```

Constructor.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array<array-key, 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**

- [`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.

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

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

Returns the configuration of core application components.

**Returns**

`array`

**See also**

- [`set()`](/docs/api/yii/di/servicelocator/index.md#method-set)

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

```php
public function end(int $status = 0, yii\base\Response|null $response = null): mixed
```

Terminates the application.

This method replaces the `exit()` function by ensuring the application life cycle is completed
before terminating the application.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$status` | `int` | The exit status (value 0 means normal exit while other values mean abnormal exit). |
| `$response` | [`Response`](/docs/api/yii/base/response/index.md)`\|null` | The response to be sent. If not set, the default application [`$response`](/docs/api/yii/base/application/index.md#property-response) component will be used. |

**Returns**

`mixed`

**Throws**

- [`ExitException`](/docs/api/yii/base/exitexception/index.md): if the application is in testing mode

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

```php
public function getAssetManager(): yii\web\AssetManager
```

Returns the asset manager.

**Returns**

[`yii\web\AssetManager`](/docs/api/yii/web/assetmanager/index.md): The asset manager application component.

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

```php
public function getAuthManager(): yii\rbac\ManagerInterface|null
```

Returns the auth manager for this application.

**Returns**

[`yii\rbac\ManagerInterface`](/docs/api/yii/rbac/managerinterface/index.md)`|null`: The auth manager application component or null if it's not configured.

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

```php
public function getCache(): yii\caching\CacheInterface|null
```

Returns the cache component.

**Returns**

[`yii\caching\CacheInterface`](/docs/api/yii/caching/cacheinterface/index.md)`|null`: The cache application component. Null if the component is not enabled.

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

```php
public function getDb(): yii\db\Connection
```

Returns the database connection component.

**Returns**

[`yii\db\Connection`](/docs/api/yii/db/connection/index.md): The database connection.

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

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

Returns the error handler component.

**Returns**

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

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

```php
public function getFormatter(): yii\i18n\Formatter
```

Returns the formatter component.

**Returns**

[`yii\i18n\Formatter`](/docs/api/yii/i18n/formatter/index.md): The formatter application component.

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

```php
public function getI18n(): yii\i18n\I18N
```

Returns the internationalization (i18n) component.

**Returns**

[`yii\i18n\I18N`](/docs/api/yii/i18n/i18n/index.md): The internationalization application component.

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

```php
public function getLog(): yii\log\Dispatcher
```

Returns the log dispatcher component.

**Returns**

[`yii\log\Dispatcher`](/docs/api/yii/log/dispatcher/index.md): The log dispatcher application component.

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

```php
public function getMailer(): yii\mail\MailerInterface
```

Returns the mailer component.

**Returns**

[`yii\mail\MailerInterface`](/docs/api/yii/mail/mailerinterface/index.md): The mailer application component.

**Throws**

- [`InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): If this component is not configured.

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

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

Returns the request component.

**Returns**

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

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

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

Returns the response component.

**Returns**

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

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

```php
public function getRuntimePath(): string
```

Returns the directory that stores runtime files.

**Returns**

`string`: The directory that stores runtime files. Defaults to the "runtime" subdirectory under [`$basePath`](/docs/api/yii/base/application/index.md#property-basePath).

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

```php
public function getSecurity(): yii\base\Security
```

Returns the security component.

**Returns**

[`Security`](/docs/api/yii/base/security/index.md): The security application component.

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

```php
public function getTimeZone(): string
```

Returns the time zone used by this application.

This is a simple wrapper of PHP function date_default_timezone_get().
If time zone is not configured in php.ini or application config,
it will be set to UTC by default.

**Returns**

`string`: The time zone used by this application.

**See also**

- <https://www.php.net/manual/en/function.date-default-timezone-get.php>

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

```php
public function getUniqueId(): string
```

Returns an ID that uniquely identifies this module among all modules within the current application.

Since this is an application instance, it will always return an empty string.

**Returns**

`string`: The unique ID of the module.

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

```php
public function getUrlManager(): yii\web\UrlManager
```

Returns the URL manager for this application.

**Returns**

[`yii\web\UrlManager`](/docs/api/yii/web/urlmanager/index.md): The URL manager for this application.

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

```php
public function getVendorPath(): string
```

Returns the directory that stores vendor files.

**Returns**

`string`: The directory that stores vendor files. Defaults to "vendor" directory under [`$basePath`](/docs/api/yii/base/application/index.md#property-basePath).

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

```php
public function getView(): yii\base\View|yii\web\View
```

Returns the view object.

**Returns**

[`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.

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

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

Handles the specified request.

This method should return an instance of [`Response`](/docs/api/yii/base/response/index.md) or its child class
which represents the handling result of the request.

**Parameters**

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

**Returns**

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

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

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

Initializes the module.

This method is called after the module is created and initialized with property values given in configuration.

The default implementation will initialize [`$controllerNamespace`](/docs/api/yii/base/application/index.md#property-controllerNamespace) if it is not set.

If you override this method, please make sure you call the parent implementation.

**Returns**

`mixed`

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

```php
public function preInit(array &$config): mixed
```

Pre-initializes the application.

This method is called at the beginning of the application constructor.
It initializes several important application properties.
If you override this method, please make sure you call the parent implementation.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array` | The application configuration |

**Returns**

`mixed`

**Throws**

- [`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.

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

```php
public function run(): int
```

Runs the application.

This is the main entrance of an application.

**Returns**

`int`: The exit status (0 means normal, non-zero values mean abnormal)

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

```php
public function setBasePath(string $path): mixed
```

Sets the root directory of the application and the @app alias.

This method can only be invoked at the beginning of the constructor.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | The root directory of the application. |

**Returns**

`mixed`

**Throws**

- [`InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the directory does not exist.

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

```php
public function setContainer(array $config): mixed
```

Configures [`Yii::$container`](/docs/api/yii/baseyii/index.md#property-container) with the $config.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array` | Values given in terms of name-value pairs |

**Returns**

`mixed`

**Since**

2.0.11

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

```php
public function setRuntimePath(string $path): mixed
```

Sets the directory that stores runtime files.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | The directory that stores runtime files. |

**Returns**

`mixed`

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

```php
public function setTimeZone(string $value): mixed
```

Sets the time zone used by this application.

This is a simple wrapper of PHP function date_default_timezone_set().
Refer to the [php manual](https://www.php.net/manual/en/timezones.php) for available timezones.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string` | The time zone used by this application. |

**Returns**

`mixed`

**See also**

- <https://www.php.net/manual/en/function.date-default-timezone-set.php>

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

```php
public function setVendorPath(string $path): mixed
```

Sets the directory that stores vendor files.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | The directory that stores vendor files. |

**Returns**

`mixed`

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

```php
protected function bootstrap(): mixed
```

Initializes extensions and executes bootstrap components.

This method is called by [`init()`](/docs/api/yii/base/application/index.md#method-init) after the application has been fully configured.
If you override this method, make sure you also call the parent implementation.

**Returns**

`mixed`

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

```php
protected function registerErrorHandler(array &$config): mixed
```

Registers the errorHandler component as a PHP error handler.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array` | Application config |

**Returns**

`mixed`