PHP SDK: Links and URL Parameters
These methods are available through $ctx->url() and operate on URL strings. Pass the resulting address to the HTTP client or browser separately.
Methods
absolutize
absolutize(string $base, string $relative): string
Resolve a relative link against a known page address.
$url = $ctx->url()->absolutize('https://shop.example.invalid/catalog/', '../product/1');
Result and notes. Returns https://shop.example.invalid/product/1. For HTML links, Node::abs() is often easier.
param
param(string $url, string $name): ?string
Read a string query parameter from a URL.
$page = $ctx->url()->param('https://shop.example.invalid/?page=3', 'page');
Result and notes. Returns the string 3 or null. Array-valued query parameters are not returned.
withParam
withParam(string $url, string $name, string|int $value): string
Add or replace one query parameter.
$url = $ctx->url()->withParam('https://shop.example.invalid/catalog?sort=price', 'page', 2);
Result and notes. Returns a URL with sort=price&page=2. Use a complete URL. The current implementation does not preserve a fragment after #.
page
page(string $template, int $page): string
Replace {page} in a template with a page number.
$url = $ctx->url()->page('https://shop.example.invalid/?PAGEN_1={page}', 4);
Result and notes. Returns an address with PAGEN_1=4. It does not determine the total number of pages or make requests.