Web\Response: add redirection function

The response now provides redirectAndExit(). One more step to clean up
our action controller. Please not that this is still unused right now.
This commit is contained in:
Thomas Gelf 2014-07-04 12:35:33 +02:00
parent 3772b9c16f
commit 3cfdf4c977
1 changed files with 16 additions and 0 deletions

View File

@ -3,7 +3,23 @@
namespace Icinga\Web;
use Zend_Controller_Response_Http;
use Icinga\Application\Icinga;
class Response extends Zend_Controller_Response_Http
{
public function redirectAndExit($url)
{
if (! $url instanceof Url) {
$url = Url::fromPath($url);
}
$url->getParams()->setSeparator('&');
if (Icinga::app()->getFrontController()->getRequest()->isXmlHttpRequest()) {
$this->setHeader('X-Icinga-Redirect', rawurlencode($url));
} else {
$this->setRedirect($url->getAbsoluteUrl());
}
$this->sendHeaders();
exit;
}
}