Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Redirect Class Reference
Inheritance diagram for Redirect:
AbstractResult ResultInterface Redirect

Public Member Functions

 __construct (App\Response\RedirectInterface $redirect, UrlInterface $urlBuilder)
 
 setRefererUrl ()
 
 setRefererOrBaseUrl ()
 
 setUrl ($url)
 
 setPath ($path, array $params=[])
 
- Public Member Functions inherited from AbstractResult
 setHttpResponseCode ($httpCode)
 
 setHeader ($name, $value, $replace=false)
 
 setStatusHeader ($httpCode, $version=null, $phrase=null)
 
 renderResult (ResponseInterface $response)
 

Protected Member Functions

 render (HttpResponseInterface $response)
 
- Protected Member Functions inherited from AbstractResult
 applyHttpHeaders (HttpResponseInterface $response)
 
 render (HttpResponseInterface $response)
 

Protected Attributes

 $redirect
 
 $urlBuilder
 
 $url
 
- Protected Attributes inherited from AbstractResult
 $httpResponseCode
 
 $headers = []
 
 $statusHeaderCode
 
 $statusHeaderVersion
 
 $statusHeaderPhrase
 

Detailed Description

In many cases controller actions may result in a redirect so this is a result object that implements all necessary properties of a HTTP redirect

@api

Since
100.0.2

Definition at line 22 of file Redirect.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( App\Response\RedirectInterface  $redirect,
UrlInterface  $urlBuilder 
)

Constructor

Parameters
App\Response\RedirectInterface$redirect
UrlInterface$urlBuilder

Definition at line 46 of file Redirect.php.

49  {
50  $this->redirect = $redirect;
51  $this->urlBuilder = $urlBuilder;
52  }

Member Function Documentation

◆ render()

render ( HttpResponseInterface  $response)
protected

{}

Definition at line 103 of file Redirect.php.

104  {
105  if (empty($this->httpResponseCode)) {
106  $response->setRedirect($this->url);
107  } else {
108  $response->setRedirect($this->url, $this->httpResponseCode);
109  }
110  return $this;
111  }
$response
Definition: 404.php:11

◆ setPath()

setPath (   $path,
array  $params = [] 
)

Set url by path

Parameters
string$path
array$params
Returns
$this

Definition at line 94 of file Redirect.php.

95  {
96  $this->url = $this->urlBuilder->getUrl($path, $this->redirect->updatePathParams($params));
97  return $this;
98  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ setRefererOrBaseUrl()

setRefererOrBaseUrl ( )

Set referer url or base if referer is not exist

Returns
$this

Definition at line 70 of file Redirect.php.

71  {
72  $this->url = $this->redirect->getRedirectUrl();
73  return $this;
74  }

◆ setRefererUrl()

setRefererUrl ( )

Set url from referer

Returns
$this

Definition at line 59 of file Redirect.php.

60  {
61  $this->url = $this->redirect->getRefererUrl();
62  return $this;
63  }

◆ setUrl()

setUrl (   $url)

URL Setter

Parameters
string$url
Returns
$this

Definition at line 81 of file Redirect.php.

82  {
83  $this->url = $url;
84  return $this;
85  }

Field Documentation

◆ $redirect

$redirect
protected

Definition at line 28 of file Redirect.php.

◆ $url

$url
protected

Definition at line 38 of file Redirect.php.

◆ $urlBuilder

$urlBuilder
protected

Definition at line 33 of file Redirect.php.


The documentation for this class was generated from the following file: