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:
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:
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:
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:
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:
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