Skip to content
PHP Ecosystem
Explore

Application

API reference › yii › web › Application

1 subclass

Application is the base class for all web application classes.

For more details and usage information on Application, see the guide article on applications.

PropertyTypeDescriptionDefined by
$actionMaparray<string, class-string|array<string, mixed>>Mapping from action IDs to standalone Action class configurations. Default: []. Available since 22.0.yii\base\Module
$actionNamespacestring|nullThe namespace where standalone Action subclasses are located for convention-based discovery, parallel to $controllerNamespace for controllers. Default: null. Available since 22.0.yii\base\Module
$aliases write-onlyarrayList of path aliases to be defined.yii\base\Module
$assetManager read-onlyAssetManagerThe asset manager application component.yii\base\Application
$authManager read-onlyyii\rbac\ManagerInterface|nullThe auth manager application component or null if it’s not configured.yii\base\Application
$basePathstringThe root directory of the application.yii\base\Application
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$bootstraparrayList of components that should be run during the application bootstrapping process. Default: [].yii\base\Application
$cache read-onlyyii\caching\CacheInterface|nullThe cache application component.yii\base\Application
$catchAllarray|nullThe configuration specifying a controller action which should handle all user requests. Default: null.Application
$charsetstringThe charset currently used for the application. Default: 'UTF-8'.yii\base\Application
$componentsarrayThe list of the component definitions or the loaded component instances (ID => definition or instance).yii\di\ServiceLocator
$container write-onlyarrayValues given in terms of name-value pairs.yii\base\Application
$controllerController|nullThe currently active controller instance Default: null.Application
$controllerMaparrayMapping from controller ID to controller configurations. Default: [].yii\base\Module
$controllerNamespacestringThe namespace that controller classes are located in. Default: 'app\controllers'.yii\base\Application
$controllerPathstringThe directory that contains the controller classes.yii\base\Module
$db read-onlyyii\db\ConnectionThe database connection.yii\base\Application
$defaultRoutestringThe default route of this application. Default: 'site'.Application
$errorHandler read-onlyErrorHandlerThe error handler application component.Application
$extensionsarray|nullList of installed Yii extensions. Default: null.yii\base\Application
$formatter read-onlyyii\i18n\FormatterThe formatter application component.yii\base\Application
$homeUrlstringThe homepage URL.Application
$i18n read-onlyyii\i18n\I18NThe internationalization application component.yii\base\Application
$idstringAn ID that uniquely identifies this module among other modules which have the same parent. Default: null.yii\base\Module
$languagestringThe language that is meant to be used for end users. Default: 'en-US'.yii\base\Application
$layoutstring|boolThe layout that should be applied for views in this application. Default: 'main'.yii\base\Application
$layoutPathstringThe root directory of layout files.yii\base\Module
$loadedModulesarrayList of loaded modules indexed by their class names. Default: [].yii\base\Application
$log read-onlyyii\log\DispatcherThe log dispatcher application component.yii\base\Application
$mailer read-onlyyii\mail\MailerInterfaceThe mailer application component.yii\base\Application
$moduleyii\base\Module|nullThe parent module of this module. null if this module does not have a parent. Default: null.yii\base\Module
$modulesarrayThe modules (indexed by their IDs).yii\base\Module
$namestringThe application name. Default: 'My Application'.yii\base\Application
$paramsarrayCustom module parameters (name => value). Default: [].yii\base\Module
$request read-onlyRequestThe request component.Application
$requestedActionyii\base\Action<yii\base\Controller>|nullThe requested Action. Default: null.yii\base\Application
$requestedParamsarray|nullThe parameters supplied to the requested action. Default: null.yii\base\Application
$requestedRoutestringThe requested route Default: null.yii\base\Application
$response read-onlyResponseThe response component.Application
$runtimePathstringThe directory that stores runtime files.yii\base\Application
$security read-onlyyii\base\SecurityThe security application component.yii\base\Application
$session read-onlySessionThe session component.Application
$sourceLanguagestringThe language that the application is written in. Default: 'en-US'.yii\base\Application
$stateintThe current application state during a request handling life cycle. Default: null.yii\base\Application
$timeZonestringThe time zone used by this application.yii\base\Application
$uniqueId read-onlystringThe unique ID of the module.yii\base\Application
$urlManager read-onlyUrlManagerThe URL manager for this application.yii\base\Application
$user read-onlyUser<yii\web\TUserIdentity>The user component.Application
$vendorPathstringThe directory that stores vendor files.yii\base\Application
$versionstring|callable|nullThe version of this module.yii\base\Module
$view read-onlyyii\base\View|ViewThe view application component that is used to render various view files.yii\base\Application
$viewPathstringThe root directory of view files.yii\base\Module
MethodDescriptionDefined by
__construct()Constructor.yii\base\Application
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Getter magic method.yii\di\ServiceLocator
__isset()Checks if a property value is null.yii\di\ServiceLocator
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
afterAction()This method is invoked right after an action within this module is executed.yii\base\Module
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
beforeAction()This method is invoked right before an action within this module is executed.yii\base\Module
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
clear()Removes the component from the locator.yii\di\ServiceLocator
coreComponents()Returns the configuration of core application components.Application
createController()Creates a controller instance based on the given route.yii\base\Module
createControllerByID()Creates a controller based on the given controller ID.yii\base\Module
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
end()Terminates the application.yii\base\Application
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
get()Returns the component instance with the specified ID.yii\base\Module
getAssetManager()Returns the asset manager.yii\base\Application
getAuthManager()Returns the auth manager for this application.yii\base\Application
getBasePath()Returns the root directory of the module.yii\base\Module
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getCache()Returns the cache component.yii\base\Application
getComponents()Returns the list of the component definitions or the loaded component instances.yii\di\ServiceLocator
getControllerPath()Returns the directory that contains the controller classes according to $controllerNamespace.yii\base\Module
getDb()Returns the database connection component.yii\base\Application
getErrorHandler()Returns the error handler component.Application
getFormatter()Returns the formatter component.yii\base\Application
getHomeUrl()Application
getI18n()Returns the internationalization (i18n) component.yii\base\Application
getInstance() staticReturns the currently requested instance of this module class.yii\base\Module
getLayoutPath()Returns the directory that contains layout view files for this module.yii\base\Module
getLog()Returns the log dispatcher component.yii\base\Application
getMailer()Returns the mailer component.yii\base\Application
getModule()Retrieves the child module of the specified ID.yii\base\Module
getModules()Returns the sub-modules in this module.yii\base\Module
getRequest()Returns the request component.Application
getResponse()Returns the response component.Application
getRuntimePath()Returns the directory that stores runtime files.yii\base\Application
getSecurity()Returns the security component.yii\base\Application
getSession()Returns the session component.Application
getTimeZone()Returns the time zone used by this application.yii\base\Application
getUniqueId()Returns an ID that uniquely identifies this module among all modules within the current application.yii\base\Application
getUrlManager()Returns the URL manager for this application.yii\base\Application
getUser()Returns the user component.Application
getVendorPath()Returns the directory that stores vendor files.yii\base\Application
getVersion()Returns current module version.yii\base\Module
getView()Returns the view object.yii\base\Application
getViewPath()Returns the directory that contains the view files for this module.yii\base\Module
handleRequest()Handles the specified request.Application
has()Returns a value indicating whether the locator has the specified component definition or has instantiated the component.yii\base\Module
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasModule()Checks whether the child module of the specified ID exists.yii\base\Module
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
init()Initializes the module.yii\base\Application
off()Detaches an existing event handler from this component.yii\base\Component
on()Attaches an event handler to an event.yii\base\Component
preInit()Pre-initializes the application.yii\base\Application
run()Runs the application.yii\base\Application
runAction()Runs a controller action specified by a route.yii\base\Module
set()Registers a component definition with this locator.yii\di\ServiceLocator
setAliases()Defines path aliases.yii\base\Module
setBasePath()Sets the root directory of the application and the @app alias.yii\base\Application
setComponents()Registers a set of component definitions in this locator.yii\di\ServiceLocator
setContainer()Configures Yii::$container with the $config.yii\base\Application
setControllerPath()Sets the directory that contains the controller classes.yii\base\Module
setHomeUrl()Application
setInstance() staticSets the currently requested instance of this module class.yii\base\Module
setLayoutPath()Sets the directory that contains the layout files.yii\base\Module
setModule()Adds a sub-module to this module.yii\base\Module
setModules()Registers sub-modules in the current module.yii\base\Module
setRuntimePath()Sets the directory that stores runtime files.yii\base\Application
setTimeZone()Sets the time zone used by this application.yii\base\Application
setVendorPath()Sets the directory that stores vendor files.yii\base\Application
setVersion()Sets current module version.yii\base\Module
setViewPath()Sets the directory that contains the view files.yii\base\Module
trigger()Triggers an event.yii\base\Component
bootstrap() protectedInitializes extensions and executes bootstrap components.Application
createStandaloneAction() protectedResolves a route to a standalone Action class through convention-based discovery under $actionNamespace.yii\base\Module
defaultVersion() protectedReturns default module version.yii\base\Module
registerErrorHandler() protectedRegisters the errorHandler component as a PHP error handler.yii\base\Application
runMappedAction() protectedRuns a standalone action registered in $actionMap.yii\base\Module
runStandaloneAction() protectedRuns a standalone Action instance through the standard module/action event lifecycle.yii\base\Module
EventTypeDescriptionDefined by
EVENT_BEFORE_REQUESTyii\base\EventAn event raised before the application starts to handle a request. Event name: 'beforeRequest'.yii\base\Application
EVENT_AFTER_REQUESTyii\base\EventAn event raised after the application successfully handles a request (before the response is sent out). Event name: 'afterRequest'.yii\base\Application
EVENT_BEFORE_ACTIONyii\base\ActionEventAn event raised before executing a controller action. Event name: 'beforeAction'.yii\base\Module
EVENT_AFTER_ACTIONyii\base\ActionEventAn event raised after executing a controller action. Event name: 'afterAction'.yii\base\Module
ConstantValueDescriptionDefined by
STATE_BEGIN0Application state used by $state: application just started.yii\base\Application
STATE_INIT1Application state used by $state: application is initializing.yii\base\Application
STATE_BEFORE_REQUEST2Application state used by $state: application is triggering EVENT_BEFORE_REQUEST.yii\base\Application
STATE_HANDLING_REQUEST3Application state used by $state: application is handling the request.yii\base\Application
STATE_AFTER_REQUEST4Application state used by $state: application is triggering EVENT_AFTER_REQUEST.yii\base\Application
STATE_SENDING_RESPONSE5Application state used by $state: application is about to send response.yii\base\Application
STATE_END6Application state used by $state: application has ended.yii\base\Application
public array|null $catchAll = null

The configuration specifying a controller action which should handle all user requests.

This is mainly used when the application is in maintenance mode and needs to handle all incoming requests via a single action. The configuration is an array whose first element specifies the route of the action. The rest of the array elements (key-value pairs) specify the parameters to be bound to the action. For example,

[
'offline/notice',
'param1' => 'value1',
'param2' => 'value2',
]

Defaults to null, meaning catch-all is not used.

public string $defaultRoute = 'site'

The default route of this application.

Defaults to ‘site’.

public function coreComponents(): array

Returns the configuration of core application components.

Returns

array

public function getErrorHandler(): yii\web\ErrorHandler

Returns the error handler component.

Returns

ErrorHandler: The error handler application component.

public function getHomeUrl(): string

Returns

string: The homepage URL

public function getRequest(): yii\web\Request

Returns the request component.

Returns

Request: The request component.

public function getResponse(): yii\web\Response

Returns the response component.

Returns

Response: The response component.

public function getSession(): yii\web\Session

Returns the session component.

Returns

Session: The session component.

public function getUser(): yii\web\User<yii\web\TUserIdentity>

Returns the user component.

Returns

User<yii\web\TUserIdentity>: The user component.

public function handleRequest(yii\web\Request $request): yii\web\Response

Handles the specified request.

Parameters

ParameterTypeDescription
$requestRequestThe request to be handled

Returns

Response: The resulting response

Throws

public function setHomeUrl(string $value): mixed

Parameters

ParameterTypeDescription
$valuestringThe homepage URL

Returns

mixed

protected function bootstrap(): mixed

Initializes extensions and executes bootstrap components.

This method is called by init() after the application has been fully configured. If you override this method, make sure you also call the parent implementation.

Returns

mixed