documentUrl.php
Table of Contents
Functions
- documentUrl() : string
- Generates a full document URL based on the project's base URL.
Functions
documentUrl()
Generates a full document URL based on the project's base URL.
documentUrl([string $path = Char::EMPTY ][, ContainerInterface|null $container = null ][, string|null $definition = 'baseUrl' ][, bool $trailingSlash = false ]) : string
This helper function is commonly used in IoC container definitions of models to generate the accessible URL of a document or resource.
The function:
- Retrieves the base URL from the DI container using the provided definition key (default 'baseUrl').
- Joins the base URL with the provided relative path.
- Optionally appends a trailing slash.
When no container is given, or when the base URL definition is absent, the base URL falls back to an empty string and only the relative path is returned.
Parameters
- $path : string = Char::EMPTY
-
Relative path of the document (default: empty string).
- $container : ContainerInterface|null = null
-
Optional DI container to fetch the base URL from.
- $definition : string|null = 'baseUrl'
-
Key used to fetch the base URL from the container (default: 'baseUrl').
- $trailingSlash : bool = false
-
Whether to append a trailing slash to the resulting URL (default: false).
Tags
Return values
string —The fully resolved document URL.