Jump to main content Jump to doc navigation

modX::makeUrl

Generates a URL representing a specified resource.

Syntax

API Doc: modX::makeUrl()

string makeUrl (integer $id, [string $context = ''], [string|array $args = ''], [mixed $scheme = -1], [array $options = null])
  • $id (integer) The id of a resource. required
  • $context (string) Specifies a context to limit URL generation to.
  • $args (string|array) A query string to append to the generated URL.
  • $scheme (string) The scheme indicates in what format the URL is generated:
    • -1: (default value) URL is relative to site_url
    • 0: see http
    • 1: see https
    • full: URL is absolute, prepended with site_url from config
    • abs or absolute: URL is absolute, prepended with base_url from config
    • http: URL is absolute, forced to http scheme
    • https: URL is absolute, forced to https scheme
  • $options (array) An array of options for generating the Resource URL.

Examples

Make a URL for the Resource with ID 4.

$url = $modx->makeUrl(4);

Make a URL for the Resource with ID 12, but make sure it's in HTTPS.

$url = $modx->makeUrl(12, '', '', 'https', array('xhtml_urls' => false));

Make a URL to Resource with ID 56, but add a ?hello=world to the URL.

$url = $modx->makeUrl(25, '', array('hello' => 'world'));
$url = $modx->makeUrl(25, '', 'hello=world');

Note that the arguments available to this function can be passed to the [[~link]] tags, e.g.

[[~123? &scheme=`full`]]

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • Chris Fickling
  • CrewMark
  • deJaya
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$301 per month—let's make that $500!

Learn more