Documentation

UrlManager

UrlManager singleton class for generating URLs for actions of AJAX-controllers.

Method Description Available from version
getInstance(
)
Returns instance \Bitrix\Main\Engine\UrlManager.
getEndPoint(
   $absolute = false
)
Gets URLs to end point, used for processing all controller actions. Parameters:
  • $absolute {bool} When true, returns absolute link with account of \Bitrix\Main\Engine\UrlManager::getHostUrl.

Example:

/** @var \Bitrix\Main\Web\Uri $endpointUri **/
$endpointUri = \Bitrix\Main\Engine\UrlManager::getInstance()->getEndPoint();
echo $endpointUri;
// /bitrix/services/main/ajax.php

$endpointUri = \Bitrix\Main\Engine\UrlManager::getInstance()->getEndPoint(true);
echo $endpointUri;
// https://example.com/bitrix/services/main/ajax.php
getHostUrl(
)
Returns absolute link for current host with port and scheme (http, https), with account of kernel settings.

Example:

/** @var string $hostUrl **/
$hostUrl = \Bitrix\Main\Engine\UrlManager::getInstance()->getHostUrl();
echo $hostUrl;
// https://example.com
create(
   $action,
   $params = [],
   $absolute = false
): \Bitrix\Main\Web\Uri
Generates link to a specific action. By default, adds SITE_ID, if known. Parameters:
  • $action {string} Full action name. For example, disk.file.get.
  • $params {array} Array with parameters to be added to query string. If required, parameters will be processed via function urlencode.
  • $absolute {bool} When set as true, returns absolute link with account of \Bitrix\Main\Engine\UrlManager::getHostUrl. False by default.

Example:

/** @var \Bitrix\Main\Web\Uri $uri **/
$uri = \Bitrix\Main\Engine\UrlManager::getInstance()->create('someModule.someController.demoAction');
echo $uri;
// /bitrix/services/main/ajax.php?action=someModule.someController.demoAction

/** @var \Bitrix\Main\Web\Uri $uri **/
$uri = \Bitrix\Main\Engine\UrlManager::getInstance()->create('someModule.someController.demoAction', ['hello' => 'world']);
echo $uri;
// /bitrix/services/main/ajax.php?action=someModule.someController.demoAction&hello=world
createByController(
   Controller $controller, 
   $action, 
   $params = [],
   $absolute = false
): \Bitrix\Main\Web\Uri
Generates link to action inside the controller class. Full path to controller will be calculated automatically based in controller instance. Parameters:
  • $controller {Controller} Instance \Bitrix\Main\Engine\Controller for which the link will be generated.
  • $action {string} Action name, directly inside $controller. For example, get.
  • $params {array} Array with parameters to be added to query string. If required, parameters will be processed via the function urlencode.
  • $absolute {bool} When set as true, returns absolute link with account of \Bitrix\Main\Engine\UrlManager::getHostUrl. False by default.

Example:

/** @var \Bitrix\Disk\Controller\File $controller */
$controller = new \Bitrix\Disk\Controller\File();
$uri = \Bitrix\Main\Engine\UrlManager::getInstance()->createByController($controller, 'get', ['id' => 100]);
echo $uri;
// /bitrix/services/main/ajax.php?action=disk.controller.file.get&id=100
createByComponentController(
   Controller $controller,
   $action,
   $params = [],
   $absolute = false
): \Bitrix\Main\Web\Uri
Creates link for action inside component controller class (in the ajax.php file). Full path to controller will be calculated automatically based on component controller instance. Parameters:
  • $controller {Controller} Instance \Bitrix\Main\Engine\Controller for which the link will be generated. Attention! This controller located inside the component, in the ajax.php file.
  • $action {string} Action name, directly inside $controller. For example, showSpace.
  • $params {array} Array with parameters to be added to query string. If required, parameters will be processed via the function urlencode.
  • $absolute {bool} When set to true, returns absolute link with account of \Bitrix\Main\Engine\UrlManager::getHostUrl.False by default.

Example

/** @var \SomeComponentController $controller */
$controller = new \SomeComponentController();
$uri = \Bitrix\Main\Engine\UrlManager::getInstance()->createByComponentController($controller, 'showSpace', ['number' => 42]);
echo $uri;
// /bitrix/services/main/ajax.php?c=bitrix:list.example&mode=ajax&action=showSpace&number=42
createByBitrixComponent(
   \CBitrixComponent $component, 
   $action,
   $params = array(),
   $absolute = false
): \Bitrix\Main\Web\Uri
Creates link for action inside component class. The full path will be calculated automatically based on the component instance. Parameters:
  • $component {\CBitrixComponent} Instance \CBitrixComponent, for which the link will be generated.
  • $action {string} Action name, directly inside $controller. For example, get.
  • $params {array} Array with parameters to be added to query string. If required, parameters will be processed via the function urlencode.
  • $absolute {bool} When set as true, returns absolute link with account of \Bitrix\Main\Engine\UrlManager::getHostUrl. False by default.

Example

/** @var \ListExampleComponent $component */
$component = new \ListExampleComponent();
$uri = \Bitrix\Main\Engine\UrlManager::getInstance()->createByBitrixComponent($component, 'get', ['id' => 40]);
echo $uri;
// /bitrix/services/main/ajax.php?c=bitrix:list.example&mode=class&action=get&id=40


© «Bitrix24», 2001-2024
Up