Class yii\web\Application

Inheritanceyii\web\Application » yii\base\Application » yii\base\Module » yii\di\ServiceLocator » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/web/Application.php

Application is the base class for all web application classes.

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

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$bootstrap array List of components that should be run during the application bootstrapping process. yii\base\Application
$catchAll array The configuration specifying a controller action which should handle all user requests. yii\web\Application
$charset string The charset currently used for the application. yii\base\Application
$controller yii\web\Controller The currently active controller instance yii\web\Application
$controllerMap array Mapping from controller ID to controller configurations. yii\base\Module
$controllerNamespace string The namespace that controller classes are located in. yii\base\Application
$defaultRoute string The default route of this application. yii\web\Application
$extensions array List of installed Yii extensions. yii\base\Application
$id string An ID that uniquely identifies this module among other modules which have the same parent. yii\base\Module
$language string The language that is meant to be used for end users. yii\base\Application
$layout string|boolean The layout that should be applied for views in this application. yii\base\Application
$loadedModules array List of loaded modules indexed by their class names. yii\base\Application
$module yii\base\Module The parent module of this module. yii\base\Module
$name string The application name. yii\base\Application
$params array Custom module parameters (name => value). yii\base\Module
$requestedAction yii\base\Action The requested Action. yii\base\Application
$requestedParams array The parameters supplied to the requested action. yii\base\Application
$requestedRoute string The requested route yii\base\Application
$sourceLanguage string The language that the application is written in. yii\base\Application
$state integer The current application state during a request handling life cycle. yii\base\Application

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__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
__construct() Constructor. yii\base\Application
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__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() Returns the fully qualified name of this class. yii\base\BaseObject
clear() Removes the component from the locator. yii\di\ServiceLocator
coreComponents() {@inheritdoc} yii\web\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() {@inheritdoc} 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. yii\web\Application
getFormatter() Returns the formatter component. yii\base\Application
getHomeUrl() yii\web\Application
getI18n() Returns the internationalization (i18n) component. yii\base\Application
getInstance() Returns 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. yii\web\Application
getResponse() Returns the response component. yii\web\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. yii\web\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. yii\web\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. yii\web\Application
has() {@inheritdoc} 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() {@inheritdoc} 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
setHomeUrl() yii\web\Application
setInstance() Sets 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

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
bootstrap() {@inheritdoc} yii\web\Application
defaultVersion() Returns default module version. yii\base\Module
registerErrorHandler() Registers the errorHandler component as a PHP error handler. yii\base\Application

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_AFTER_ACTION yii\base\ActionEvent An event raised after executing a controller action. yii\base\Module
EVENT_AFTER_REQUEST yii\base\Event An event raised after the application successfully handles a request (before the response is sent out). yii\base\Application
EVENT_BEFORE_ACTION yii\base\ActionEvent An event raised before executing a controller action. yii\base\Module
EVENT_BEFORE_REQUEST yii\base\Event An event raised before the application starts to handle a request. yii\base\Application

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
STATE_AFTER_REQUEST 4 Application state used by $state: application is triggering EVENT_AFTER_REQUEST. . yii\base\Application
STATE_BEFORE_REQUEST 2 Application state used by $state: application is triggering EVENT_BEFORE_REQUEST. yii\base\Application
STATE_BEGIN 0 Application state used by $state: application just started. yii\base\Application
STATE_END 6 Application state used by $state: application has ended. yii\base\Application
STATE_HANDLING_REQUEST 3 Application state used by $state: application is handling the request. yii\base\Application
STATE_INIT 1 Application state used by $state: application is initializing. yii\base\Application
STATE_SENDING_RESPONSE 5 Application state used by $state: application is about to send response. yii\base\Application

Property Details

$catchAll public property

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 array $catchAll null
$controller public property

The currently active controller instance

$defaultRoute public property

The default route of this application. Defaults to 'site'.

public string $defaultRoute 'site'

Method Details

bootstrap() protected method

{@inheritdoc}

protected void bootstrap ( )
coreComponents() public method

{@inheritdoc}

public void coreComponents ( )
getErrorHandler() public method

Returns the error handler component.

public yii\web\ErrorHandler getErrorHandler ( )
return yii\web\ErrorHandler

The error handler application component.

getHomeUrl() public method

public string getHomeUrl ( )
return string

The homepage URL

getRequest() public method

Returns the request component.

public yii\web\Request getRequest ( )
return yii\web\Request

The request component.

getResponse() public method

Returns the response component.

public yii\web\Response getResponse ( )
return yii\web\Response

The response component.

getSession() public method

Returns the session component.

public yii\web\Session getSession ( )
return yii\web\Session

The session component.

getUser() public method

Returns the user component.

public yii\web\User getUser ( )
return yii\web\User

The user component.

handleRequest() public method

Handles the specified request.

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

The request to be handled

return yii\web\Response

The resulting response

throws yii\web\NotFoundHttpException

if the requested route is invalid

setHomeUrl() public method

public void setHomeUrl ( $value )
$value string

The homepage URL