Symfony\Component\HttpFoundation\RedirectResponse::__construct PHP Method

__construct() public method

Creates a redirect response so that it conforms to the rules defined for a redirect status code.
See also: http://tools.ietf.org/html/rfc2616#section-10.3
public __construct ( string $url, integer $status = 302 )
$url string The URL to redirect to
$status integer The status code (302 by default)
    public function __construct($url, $status = 302)
    {
        if (empty($url)) {
            throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
        }

        parent::__construct(
            sprintf('<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="refresh" content="1;url=%1$s" />
    </head>
    <body>
        Redirecting to <a href="%1$s">%1$s</a>.
    </body>
</html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')),
            $status,
            array('Location' => $url)
        );

        if (!$this->isRedirect()) {
            throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
        }
    }

Usage Example

Example #1
0
 /**
  * @param Request $request
  * @param View $view
  * @param Session $session
  * @param array|string $url
  * @param int $status
  * @param array $headers
  */
 public function __construct(Request $request, View $view, Session $session, $url = ROOT, $status = 302, $headers = array())
 {
     $this->request = $request;
     $this->view = $view;
     $this->session = $session;
     parent::__construct($url, $status, $headers);
 }
All Usage Examples Of Symfony\Component\HttpFoundation\RedirectResponse::__construct
RedirectResponse