PageTraversal::urlOptions()

Returns the URL to the page with $options

You can specify an $options argument to this method with any of the following:

  • pageNum (int|string|bool): Specify pagination number, "+" for next pagination, "-" for previous pagination, or true for current.
  • urlSegmentStr (string|bool): Specify a URL segment string to append, or true 3.0.155+ for current.
  • urlSegments (array|bool): Specify regular array of URL segments to append (may be used instead of urlSegmentStr). Specify boolean true for current URL segments 3.0.155+. Specify associative array (in 3.0.155+ to make both keys and values part of the URL segment string.
  • data (array): Array of key=value variables to form a query string.
  • http (bool): Specify true to make URL include scheme and hostname Default:false
  • scheme (string): Like the http option, makes URL include scheme and hostname, but you specify scheme with this, i.e. 'https' 3.0.178+
  • host (string): Hostname to force use of, i.e. 'world.com' or 'hello.world.com'. The 'http' option is implied when host specified. 3.0.178+
  • language (Language): Specify Language object to return URL in that Language.

You can also specify any of the following for $options as shortcuts:

  • If you specify an int for options it is assumed to be the pageNum option.
  • If you specify + or - for options it is assumed to be the pageNum “next/previous pagination” option.
  • If you specify any other string for options it is assumed to be the urlSegmentStr option.
  • If you specify a boolean (true) for options it is assumed to be the http option.

Please also note regarding $options:

  • This method honors template slash settings for page, URL segments and page numbers.
  • Any passed in URL segments are automatically sanitized with Sanitizer::pageNameUTF8().
  • If using the pageNum or URL segment options please also make sure these are enabled on the page’s template.
  • The query string generated by any data variables is entity encoded when output formatting is on.
  • The language option requires that the LanguageSupportPageNames module is installed.
  • The prefix for page numbers honors $config->pageNumUrlPrefix and multi-language prefixes as well.

Usage

// basic usage
$string = $pageTraversal->urlOptions(Page $page);

// usage with all arguments
$string = $pageTraversal->urlOptions(Page $page, $options = []);

Arguments

NameType(s)Description
$pagePage
$options (optional)array int string bool Language

Optionally specify options to modify default behavior (see method description).

Return value

string

Returns page URL, for example: /my-site/about/contact/

See Also


PageTraversal methods and properties

API reference based on ProcessWire core version 3.0.255