added Response::setRedirect()
This commit is contained in:
parent
ef0347c1b9
commit
f61bb19548
@ -106,11 +106,7 @@ class Controller
|
||||
*/
|
||||
public function redirect($url, $status = 302)
|
||||
{
|
||||
$response = $this->container->get('response');
|
||||
$response->setStatusCode($status);
|
||||
$response->headers->set('Location', $url);
|
||||
|
||||
return $response;
|
||||
return $this->container->get('response')->setRedirect($url, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -535,6 +535,26 @@ class Response
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the response so that it conforms to the rules defined for a redirect status code.
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc2616#section-10.3.5
|
||||
*/
|
||||
public function setRedirect($url, $status = 302)
|
||||
{
|
||||
if (empty($url)) {
|
||||
throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
|
||||
}
|
||||
|
||||
$this->setStatusCode($status);
|
||||
if (!$this->isRedirect()) {
|
||||
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
|
||||
}
|
||||
|
||||
$this->headers->set('Location', $url);
|
||||
$this->setContent(sprintf('<html><head><meta http-equiv="refresh" content="1;url=%s"/></head></html>', htmlspecialchars($url, ENT_QUOTES)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the response includes a Vary header.
|
||||
*
|
||||
|
Reference in New Issue
Block a user