Views: 852 (Data available since 06.02.2017)
Last Modified: 01.07.2014
Attention! The functionality is not supported so far. The commencement of support services will be additionally announced.

Application is an object responsible for core initialization.

The application is the entry base point (router) for query to core global entities: connection with data sources, mastered cache, etc. Also, the application contains global data that belong to the site itself and do not depend on a specific hit. I.e. the application is an unchanged part not dependent on a specific hit.

Any specific class of application is a successor of the abstract class Bitrix\Main\Application. Two specific classes of the application are supported – Bitrix\Main\HttpApplication and Bitrix\Main\CliApplication that are the successors of the class Bitrix\Main\Application, but implement a slightly different execution logic.

The specific class Bitrix\Main\HttpApplication is responsible for a regular http hit on the site.

The application supports the Singleton template. I.e. as a part of the hit there is only one copy of a specific type of application. It can be obtained using the instruction:

$application = Application::getInstance();

Context is an object responsible for a specific hit. It contains a query of a current hit, response to it, and also the server parameters of the current hit. I.e. it is a variable part that depends on the current hit.

Any specific class of a context is a successor of the abstract class Bitrix\Main\Context. Two specific classes of the context are supported – Bitrix\Main\HttpContext and Bitrix\Main\CliContext. The specific class Bitrix\Main\HttpContext is responsible for a regular http hit on the site.

The following code may be used in order to obtain a context of the current hit execution:

$context = Application::getInstance()->getContext();

If the application of the Bitrix\Main\HttpApplication type was initiated, this call will bring an instance of the Bitrix\Main\HttpContext context type.

The context contains a query of the current hit. In order to receive the query the following code may be used:

$context = Application::getInstance()->getContext();
$request = $context->getRequest();

Note: In all the examples, a full form of record is used (sometimes without indicating name spaces) that permits you to obtain the result from any code point. However, short forms may exist for this specific code point in order to access the result.

A request is a class instance that is a successor of the Bitrix\Main\Request class. In case of a normal http request the request will be a class instance of Bitrix\Main\HttpRequest that extends Bitrix\Main\Request. This class is a dictionary providing access to “key-value” pairs of incoming parameters.

The following code may be used in order to access an incoming parameter transmitted by the GET or POST methods:

$value = $request->get("some_name");
$value = $request["some_name"];

Other useful query methods:

$value = $request->getQuery("some_name");   // receive GET parameter
$value = $request->getPost("some_name");   // receive POST parameter
$value = $request->getFile("some_name");   // receive downloaded file
$value = $request->getCookie("some_name");   // receive cookie value
$uri = $request->getRequestUri();   // receive an address requested
$method = $request->getRequestMethod();   // receive a request method
$flag = $request->isPost();      // true - POST-request, otherwise false


Courses developed by «Bitrix», Inc.