Class RedirectResponse

Summary

Fully Qualified Name: CodeIgniter\HTTP\RedirectResponse
Extends: Response

Description

Handle a redirect response

Methods

Name Description Defined By
__construct() Constructor Response
appendBody() Appends data to the body of the current message. Message
appendHeader() Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess) Message
back() Helper function to return to previous page. RedirectResponse
deleteCookie() Sets a cookie to be deleted when the response is sent. Response
download() Force a download. Response
getBody() Grabs the current body. Response
getCookie() Returns the cookie Response
getHeader() Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects. Message
getHeaderLine() Retrieves a comma-separated string of the values for a single header. Message
getHeaders() Returns an array containing all headers. Message
getJSON() Returns the current body, converted to JSON is it isn't already. Response
getProtocolVersion() Returns the HTTP Protocol Version. Message
getReason() Gets the response response phrase associated with the status code. Response
getStatusCode() Gets the response status code. Response
getXML() Retrieves the current body into XML and returns it. Response
hasCookie() Checks to see if the Response has a specified cookie or not. Response
hasHeader() Determines whether a header exists. Message
noCache() Sets the appropriate headers to ensure this response is not cached by the browsers. Response
populateHeaders() Populates the $headers array with any headers the getServer knows about. Message
prependHeader() Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess) Message
pretend() Turns "pretend" mode on or off to aid in testing. Response
redirect() Perform a redirect to a new URL, in two flavors: header or location. Response
removeHeader() Removes a header from the list of headers we track. Message
route() Sets the URI to redirect to but as a reverse-routed or named route instead of a raw URI. RedirectResponse
send() Sends the output to the browser. Response
sendBody() Sends the Body of the message to the browser. Response
sendHeaders() Sends the headers of this HTTP request to the browser. Response
setBody() Sets the body of the current message. Message
setCache() A shortcut method that allows the developer to set all of the cache-control headers in one method call. Response
setContentType() Sets the Content Type header for this response with the mime type and, optionally, the charset. Response
setCookie() Set a cookie Response
setDate() Sets the date header Response
setHeader() Sets a header and it's value. Message
setJSON() Converts the $body into JSON and sets the Content Type header. Response
setLastModified() Sets the Last-Modified date header. Response
setLink() Set the Link Header Response
setProtocolVersion() Sets the HTTP protocol version. Message
setStatusCode() Return an instance with the specified status code and, optionally, reason phrase. Response
setXML() Converts $body into XML, and sets the correct Content-Type. Response
to() Sets the URI to redirect to and, optionally, the HTTP status code to use. RedirectResponse
with() Adds a key and message to the session as Flashdata. RedirectResponse
withInput() Specifies that the current $_GET and $_POST arrays should be packaged up with the response. It will then be available via the 'old()' helper function. RedirectResponse

Method Details

__construct()

Constructor

Parameter Name Type Description
$config \App

Returns:

appendBody()

Appends data to the body of the current message.

Parameter Name Type Description
$data
$data

Returns: \Message|\Response

appendHeader()

Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)

Parameter Name Type Description
$name string
$value string

Returns: \Message

back()

Helper function to return to previous page.

Example: return redirect()->back();

Parameter Name Type Description
$code int|null
$method string

Returns: $this

deleteCookie()

Sets a cookie to be deleted when the response is sent.

Parameter Name Type Description
$name string
$domain string
$path string
$prefix string

Returns: $this

download()

Force a download.

Generates the headers that force a download to happen. And sends the file to the browser.

Parameter Name Type Description
$filename string The
$data string|null The
$setMime bool Whether

Returns: \CodeIgniter\HTTP\DownloadResponse|null

getBody()

Grabs the current body.

Returns: mixed|string

getCookie()

Returns the cookie

Parameter Name Type Description
$name string|null
$prefix string

Returns: mixed

getHeader()

Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects.

Parameter Name Type Description
$name string

Returns: array|\CodeIgniter\HTTP\Header

getHeaderLine()

Retrieves a comma-separated string of the values for a single header.

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

Parameter Name Type Description
$name string

Returns: string

getHeaders()

Returns an array containing all headers.

Returns: array An array of the request headers

getJSON()

Returns the current body, converted to JSON is it isn't already.

Returns: mixed|string

getProtocolVersion()

Returns the HTTP Protocol Version.

Returns: string

getReason()

Gets the response response phrase associated with the status code.

Returns: string

getStatusCode()

Gets the response status code.

The status code is a 3-digit integer result code of the getServer's attempt to understand and satisfy the request.

Returns: int Status code.

getXML()

Retrieves the current body into XML and returns it.

Returns: mixed|string

hasCookie()

Checks to see if the Response has a specified cookie or not.

Parameter Name Type Description
$name string
$value string|null
$prefix string

Returns: bool

hasHeader()

Determines whether a header exists.

Parameter Name Type Description
$name string

Returns: bool

noCache()

Sets the appropriate headers to ensure this response is not cached by the browsers.

Returns: \Response

populateHeaders()

Populates the $headers array with any headers the getServer knows about.

Returns:

prependHeader()

Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)

Parameter Name Type Description
$name string
$value string

Returns: \Message

pretend()

Turns "pretend" mode on or off to aid in testing.

Parameter Name Type Description
$pretend bool

Returns: $this

redirect()

Perform a redirect to a new URL, in two flavors: header or location.

Parameter Name Type Description
$uri string The
$method string
$code int The

Returns: $this

removeHeader()

Removes a header from the list of headers we track.

Parameter Name Type Description
$name string

Returns: \Message

route()

Sets the URI to redirect to but as a reverse-routed or named route instead of a raw URI.

Parameter Name Type Description
$route string
$params array
$code int|null
$method string

Returns: $this

send()

Sends the output to the browser.

Returns: \Response

sendBody()

Sends the Body of the message to the browser.

Returns: \Response

sendHeaders()

Sends the headers of this HTTP request to the browser.

Returns: \Response

setBody()

Sets the body of the current message.

Parameter Name Type Description
$data mixed

Returns: \Message|\Response

setCache()

A shortcut method that allows the developer to set all of the cache-control headers in one method call.

The options array is used to provide the cache-control directives for the header. It might look something like:

 $options = [
     'max-age'  => 300,
     's-maxage' => 900
     'etag'     => 'abcde',
 ];

Typical options are:

Parameter Name Type Description
$options array

Returns: \Response

setContentType()

Sets the Content Type header for this response with the mime type and, optionally, the charset.

Parameter Name Type Description
$mime string
$charset string

Returns: \Response

setCookie()

Set a cookie

Accepts an arbitrary number of binds (up to 7) or an associative array in the first parameter containing all the values.

Parameter Name Type Description
$name string|array Cookie
$value string Cookie
$expire string Cookie
$domain string Cookie
$path string Cookie
$prefix string Cookie
$secure bool Whether
$httponly bool Whether

Returns: $this

setDate()

Sets the date header

Parameter Name Type Description
$date \DateTime

Returns: \Response

setHeader()

Sets a header and it's value.

Parameter Name Type Description
$name string
$value array|null|string

Returns: \Message|\Response

setJSON()

Converts the $body into JSON and sets the Content Type header.

Parameter Name Type Description
$body array|string
$unencoded

Returns: $this

setLastModified()

Sets the Last-Modified date header.

$date can be either a string representation of the date or, preferably, an instance of DateTime.

Parameter Name Type Description
$date \DateTime|string

Returns: \Response

setLink()

Set the Link Header

Parameter Name Type Description
$pager \CodeIgniter\Pager\PagerInterface

Returns: \Response

setProtocolVersion()

Sets the HTTP protocol version.

Parameter Name Type Description
$version string

Returns: \Message

setStatusCode()

Return an instance with the specified status code and, optionally, reason phrase.

If no reason phrase is specified, will default recommended reason phrase for the response's status code.

Parameter Name Type Description
$code int The
$reason string The

Returns: $this

setXML()

Converts $body into XML, and sets the correct Content-Type.

Parameter Name Type Description
$body array|string

Returns: $this

to()

Sets the URI to redirect to and, optionally, the HTTP status code to use.

If no code is provided it will be automatically determined.

Parameter Name Type Description
$uri string The
$code int|null HTTP
$method string

Returns: $this

with()

Adds a key and message to the session as Flashdata.

Parameter Name Type Description
$key string
$message string|array

Returns: $this

withInput()

Specifies that the current $_GET and $_POST arrays should be packaged up with the response. It will then be available via the 'old()' helper function.

Returns: $this

Top