1 follower

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
$aliases array List of path aliases to be defined. The array keys are alias names (must start with @) and the array values are the corresponding paths or aliases. See setAliases() for an example. This property is write-only. yii\base\Module
$assetManager yii\web\AssetManager The asset manager application component. This property is read-only. yii\base\Application
$authManager yii\rbac\ManagerInterface The auth manager application component. Null is returned if auth manager is not configured. This property is read-only. yii\base\Application
$basePath string The root directory of the application. yii\base\Application
$behaviors yii\base\Behavior[] List of behaviors attached to this component. This property is read-only. yii\base\Component
$bootstrap array List of components that should be run during the application bootstrapping process. yii\base\Application
$cache yii\caching\CacheInterface The cache application component. Null if the component is not enabled. This property is read-only. 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
$components array The list of the component definitions or the loaded component instances (ID => definition or instance). yii\di\ServiceLocator
$container array Values given in terms of name-value pairs. This property is write-only. 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
$controllerPath string The directory that contains the controller classes. This property is read-only. yii\base\Module
$db yii\db\Connection The database connection. This property is read-only. yii\base\Application
$defaultRoute string The default route of this application. yii\web\Application
$errorHandler yii\web\ErrorHandler The error handler application component. This property is read-only. yii\web\Application
$extensions array List of installed Yii extensions. yii\base\Application
$formatter yii\i18n\Formatter The formatter application component. This property is read-only. yii\base\Application
$homeUrl string The homepage URL. yii\web\Application
$i18n yii\i18n\I18N The internationalization application component. This property is read-only. 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
$layoutPath string The root directory of layout files. Defaults to "$viewPath/layouts". yii\base\Module
$loadedModules array List of loaded modules indexed by their class names. yii\base\Application
$log yii\log\Dispatcher The log dispatcher application component. This property is read-only. yii\base\Application
$mailer yii\mail\MailerInterface The mailer application component. This property is read-only. yii\base\Application
$module yii\base\Module|null The parent module of this module. yii\base\Module
$modules array The modules (indexed by their IDs). yii\base\Module
$name string The application name. yii\base\Application
$params array Custom module parameters (name => value). yii\base\Module
$request yii\web\Request The request component. This property is read-only. yii\web\Application
$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
$response yii\web\Response The response component. This property is read-only. yii\web\Application
$runtimePath string The directory that stores runtime files. Defaults to the "runtime" subdirectory under $basePath. yii\base\Application
$security yii\base\Security The security application component. This property is read-only. yii\base\Application
$session yii\web\Session The session component. This property is read-only. yii\web\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
$timeZone string The time zone used by this application. yii\base\Application
$uniqueId string The unique ID of the module. This property is read-only. yii\base\Application
$urlManager yii\web\UrlManager The URL manager for this application. This property is read-only. yii\base\Application
$user yii\web\User The user component. This property is read-only. yii\web\Application
$vendorPath string The directory that stores vendor files. Defaults to "vendor" directory under $basePath. yii\base\Application
$version string The version of this module. Note that the type of this property differs in getter and setter. See getVersion() and setVersion() for details. yii\base\Module
$view yii\base\View|yii\web\View The view application component that is used to render various view files. This property is read-only. yii\base\Application
$viewPath string The root directory of view files. Defaults to "$basePath/views". yii\base\Module

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() Returns the configuration of core application components. 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() 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. 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() 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
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() Initializes extensions and executes bootstrap components. 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'
$errorHandler public property

The error handler application component. This property is read-only.

$homeUrl public property

The homepage URL.

public string $homeUrl null
$request public property

The request component. This property is read-only.

public yii\web\Request $request null
$response public property

The response component. This property is read-only.

$session public property

The session component. This property is read-only.

public yii\web\Session $session null
$user public property

The user component. This property is read-only.

public yii\web\User $user null

Method Details

bootstrap() protected method

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.

protected void bootstrap ( )
coreComponents() public method

Returns the configuration of core application components.

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