modX.sendForward
Last updated Nov 27th, 2019 | Page history | Improve this page | Report an issue
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
Budget
$311 per month—let's make that $500!
Learn moremodX::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, usemodX::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. Thecontent
,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
Budget
$311 per month—let's make that $500!
Learn more