Added the setLocation() method for Output.
Useful for redirecting the user to a different page and automatically setting the correct status header.
This commit is contained in:
parent
d6863d3f51
commit
58e885e35f
|
@ -522,4 +522,25 @@ class Output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the location to redirect the user to.
|
||||||
|
*
|
||||||
|
* @param string $locationUrl Should be prepended with /
|
||||||
|
* @param bool $permanent True for 301, false for 302 redirect.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setLocation(string $locationUrl, bool $permanent = false)
|
||||||
|
{
|
||||||
|
// Set the status header
|
||||||
|
if ($permanent)
|
||||||
|
$this->setStatusHeader(301);
|
||||||
|
else
|
||||||
|
$this->setStatusHeader(302);
|
||||||
|
|
||||||
|
// And the location itself
|
||||||
|
$header = 'Location: ' . $locationUrl;
|
||||||
|
$this->headers[] = [$header, true];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue