Jump to main content Jump to doc navigation

modX::sendForward

Forwards the request to another resource without changing the URL. If the ID provided does not exist, sends to a 404 Error page.

Syntax

API Doc: modX::sendForward()

void sendForward (integer $id, [string|array $options = null], [boolean $sendErrorPage = true])
  • $id is a Resource ID (you cannot sendForward to an URL - if you need to pass some value, use modX::setPlaceholder and call that on the target resource).
  • $options is assumed to be a proper HTTP response code when it is a string, eg "HTTP/1.1 301 Moved Permanently". If it's an array, you can use the following options:
    • response_code: response code, please see example below
    • error_type: response code type, please see example below. F.e. 404
    • error_header: "Header:" value
    • error_pagetitle: error pagetitle value
    • error_message: error message
    • merge: a way to merge the resource currently in $modx->resource with the target resource. The content, pub_date, unpub_date, richtext, _content and _processed values are excluded as well as the value of the forward_merge_excludes system setting. I'm not sure if this is supposed to be used out of the core and there's probably better ways to get data combined (eg: setPlaceholder) then merging.
  • $sendErrorPage Whether we should skip the sendErrorPage if the resource does not exist.

Example

Send the user to Resource ID 234 without actually changing the URL.

$modx->sendForward(234);

Send user to 404 Error page, for actual page ID we use error_page system setting value. If there is no such value, the value of site_start will be used.

$options = array(
   'response_code' => '404 Not Found',
   'error_type' => '404',
   'error_header' => '404 Not Found',
   'error_pagetitle' => 'Error 404: Page not found',
   'error_message' => '<h1>Page not found</h1><p>The page you requested was not found.</p>'
);
$this->sendForward($this->getOption('error_page', $options, $this->getOption('site_start')), $options, false);

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
  • CrewMark
  • Chris Fickling
  • 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