You are here

public function RedirectResponse::setTargetUrl in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/RedirectResponse.php \Symfony\Component\HttpFoundation\RedirectResponse::setTargetUrl()

Sets the redirect target of this response.

Parameters

string $url The URL to redirect to:

Return value

RedirectResponse The current response.

Throws

\InvalidArgumentException

2 calls to RedirectResponse::setTargetUrl()
RedirectResponse::__construct in vendor/symfony/http-foundation/RedirectResponse.php
Creates a redirect response so that it conforms to the rules defined for a redirect status code.
SecuredRedirectResponse::setTargetUrl in core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php
Sets the redirect target of this response.
1 method overrides RedirectResponse::setTargetUrl()
SecuredRedirectResponse::setTargetUrl in core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php
Sets the redirect target of this response.

File

vendor/symfony/http-foundation/RedirectResponse.php, line 76

Class

RedirectResponse
RedirectResponse represents an HTTP response doing a redirect.

Namespace

Symfony\Component\HttpFoundation

Code

public function setTargetUrl($url) {
  if (empty($url)) {
    throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
  }
  $this->targetUrl = $url;
  $this
    ->setContent(sprintf('<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="1;url=%1$s" />

        <title>Redirecting to %1$s</title>
    </head>
    <body>
        Redirecting to <a href="%1$s">%1$s</a>.
    </body>
</html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')));
  $this->headers
    ->set('Location', $url);
  return $this;
}