Свойство | Type | Description | |
---|---|---|---|
$acceptMimeType | the MIME type (e.g. application/json) from the request ACCEPT header chosen for this response. This property is mainly set by ContentNegotiator. | ||
$acceptParams | the parameters (e.g. ['q' => 1, 'version' => '1.0']) associated with the [[acceptMimeType|chosen MIME type]]. This is a list of name-value pairs associated with [[acceptMimeType]] from the ACCEPT HTTP header. This property is mainly set by ContentNegotiator. | ||
$charset | the charset of the text response. If not set, it will use the value of [[Application::charset]]. | ||
$content | the response content. When [[data]] is not null, it will be converted into [[content]] according to [[format]] when the response is being sent out. | ||
$data | the original response data. When this is not null, it will be converted into [[content]] according to [[format]] when the response is being sent out. | ||
$format | the response format. This determines how to convert [[data]] into [[content]] when the latter is not set. The value of this property must be one of the keys declared in the [[formatters]] array. By default, the following formats are supported: - [[FORMAT_RAW]]: the data will be treated as the response content without any conversion. No extra HTTP header will be added. - [[FORMAT_HTML]]: the data will be treated as the response content without any conversion. The "Content-Type" header will set as "text/html". - [[FORMAT_JSON]]: the data will be converted into JSON format, and the "Content-Type" header will be set as "application/json". - [[FORMAT_JSONP]]: the data will be converted into JSONP format, and the "Content-Type" header will be set as "text/javascript". Note that in this case $data must be an array with "data" and "callback" elements. The former refers to the actual data to be sent, while the latter refers to the name of the JavaScript callback. - [[FORMAT_XML]]: the data will be converted into XML format. Please refer to XmlResponseFormatter for more details. You may customize the formatting process or support additional formats by configuring [[formatters]]. | ||
$formatters | the formatters for converting data into the response content of the specified [[format]]. The array keys are the format names, and the array values are the corresponding configurations for creating the formatter objects. | ||
$httpStatuses | list of HTTP status codes and the corresponding texts | ||
$isSent | whether the response has been sent. If this is true, calling Response::send will do nothing. | ||
$statusText | the HTTP status description that comes together with the status code. | ||
$stream | the stream to be sent. This can be a stream handle or an array of stream handle, the begin position and the end position. Note that when this property is set, the [[data]] and [[content]] properties will be ignored by Response::send. | ||
$version | the version of the HTTP protocol to use. If not set, it will be determined via $_SERVER['SERVER_PROTOCOL'], or '1.1' if that is not available. |
Méthode | Description | |
---|---|---|
clear ( ) | Clears the headers, cookies, content, status code of the response. | |
getCookies ( ) : |
Returns the cookie collection. | |
getHeaders ( ) : |
Returns the header collection. | |
getIsClientError ( ) : boolean | ||
getIsEmpty ( ) : boolean | ||
getIsForbidden ( ) : boolean | ||
getIsInformational ( ) : boolean | ||
getIsInvalid ( ) : boolean | ||
getIsNotFound ( ) : boolean | ||
getIsOk ( ) : boolean | ||
getIsRedirection ( ) : boolean | ||
getIsServerError ( ) : boolean | ||
getIsSuccessful ( ) : boolean | ||
getStatusCode ( ) : integer | ||
init ( ) | Initializes this component. | |
redirect ( string | array $url, integer $statusCode = 302, boolean $checkAjax = true ) | Redirects the browser to the specified URL. | |
refresh ( string $anchor = '' ) : |
Refreshes the current page. | |
send ( ) | Sends the response to the client. | |
sendContentAsFile ( string $content, string $attachmentName, array $options = [] ) | Sends the specified content as a file to the browser. | |
sendFile ( string $filePath, string $attachmentName = null, array $options = [] ) | Sends a file to the browser. | |
sendStreamAsFile ( resource $handle, string $attachmentName, array $options = [] ) | Sends the specified stream as a file to the browser. | |
setDownloadHeaders ( string $attachmentName, string $mimeType = null, boolean $inline = false, integer $contentLength = null ) | Sets a default set of HTTP headers for file downloading purpose. | |
setStatusCode ( integer $value, string $text = null ) | Sets the response status code. | |
xSendFile ( string $filePath, string $attachmentName = null, array $options = [] ) | Sends existing file to a browser as a download using x-sendfile. |
Méthode | Description | |
---|---|---|
defaultFormatters ( ) : array | ||
getDispositionHeaderValue ( string $disposition, string $attachmentName ) : string | Returns Content-Disposition header value that is safe to use with both old and new browsers | |
getHttpRange ( integer $fileSize ) : array | boolean | Determines the HTTP range given in the request. | |
prepare ( ) | Prepares for sending the response. | |
sendContent ( ) | Sends the response content to the client | |
sendCookies ( ) | Sends the cookies to the client. | |
sendHeaders ( ) | Sends the response headers to the client |
public clear ( ) |
protected defaultFormatters ( ) : array | ||
Résultat | array | the formatters that are supported by default |
public getCookies ( ) : |
||
Résultat | the cookie collection. |
public getHeaders ( ) : |
||
Résultat | the header collection |
public getIsClientError ( ) : boolean | ||
Résultat | boolean | whether this response indicates a client error |
public getIsEmpty ( ) : boolean | ||
Résultat | boolean | whether this response is empty |
public getIsForbidden ( ) : boolean | ||
Résultat | boolean | whether this response indicates the current request is forbidden |
public getIsInformational ( ) : boolean | ||
Résultat | boolean | whether this response is informational |
public getIsInvalid ( ) : boolean | ||
Résultat | boolean | whether this response has a valid [[statusCode]]. |
public getIsNotFound ( ) : boolean | ||
Résultat | boolean | whether this response indicates the currently requested resource is not found |
public getIsRedirection ( ) : boolean | ||
Résultat | boolean | whether this response is a redirection |
public getIsServerError ( ) : boolean | ||
Résultat | boolean | whether this response indicates a server error |
public getIsSuccessful ( ) : boolean | ||
Résultat | boolean | whether this response is successful |
public getStatusCode ( ) : integer | ||
Résultat | integer | the HTTP status code to send with the response. |
protected prepare ( ) |
public redirect ( string | array $url, integer $statusCode = 302, boolean $checkAjax = true ) | ||
$url | string | array | the URL to be redirected to. This can be in one of the following formats: - a string representing a URL (e.g. "http://example.com") - a string representing a URL alias (e.g. "@example.com") - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`). Note that the route is with respect to the whole application, instead of relative to a controller or module. [[Url::to()]] will be used to convert the array into a URL. Any relative URL will be converted into an absolute one by prepending it with the host info of the current request. |
$statusCode | integer | the HTTP status code. Defaults to 302.
See |
$checkAjax | boolean | whether to specially handle AJAX (and PJAX) requests. Defaults to true, meaning if the current request is an AJAX or PJAX request, then calling this method will cause the browser to redirect to the given URL. If this is false, a `Location` header will be sent, which when received as an AJAX/PJAX response, may NOT cause browser redirection. Takes effect only when request header `X-Ie-Redirect-Compatibility` is absent. |
public sendContentAsFile ( string $content, string $attachmentName, array $options = [] ) | ||
$content | string | the content to be sent. The existing [[content]] will be discarded. |
$attachmentName | string | the file name shown to the user. |
$options | array | additional options for sending the file. The following options are supported: - `mimeType`: the MIME type of the content. Defaults to 'application/octet-stream'. - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, meaning a download dialog will pop up. |
public sendFile ( string $filePath, string $attachmentName = null, array $options = [] ) | ||
$filePath | string | the path of the file to be sent. |
$attachmentName | string | the file name shown to the user. If null, it will be determined from `$filePath`. |
$options | array | additional options for sending the file. The following options are supported: - `mimeType`: the MIME type of the content. If not set, it will be guessed based on `$filePath` - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, meaning a download dialog will pop up. |
public sendStreamAsFile ( resource $handle, string $attachmentName, array $options = [] ) | ||
$handle | resource | the handle of the stream to be sent. |
$attachmentName | string | the file name shown to the user. |
$options | array | additional options for sending the file. The following options are supported: - `mimeType`: the MIME type of the content. Defaults to 'application/octet-stream'. - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, meaning a download dialog will pop up. - `fileSize`: the size of the content to stream this is useful when size of the content is known and the content is not seekable. Defaults to content size using `ftell()`. This option is available since version 2.0.4. |
public setDownloadHeaders ( string $attachmentName, string $mimeType = null, boolean $inline = false, integer $contentLength = null ) | ||
$attachmentName | string | the attachment file name |
$mimeType | string | the MIME type for the response. If null, `Content-Type` header will NOT be set. |
$inline | boolean | whether the browser should open the file within the browser window. Defaults to false, meaning a download dialog will pop up. |
$contentLength | integer | the byte length of the file being downloaded. If null, `Content-Length` header will NOT be set. |
public setStatusCode ( integer $value, string $text = null ) | ||
$value | integer | the status code |
$text | string | the status text. If not set, it will be set automatically based on the status code. |
public xSendFile ( string $filePath, string $attachmentName = null, array $options = [] ) | ||
$filePath | string | file name with full path |
$attachmentName | string | file name shown to the user. If null, it will be determined from `$filePath`. |
$options | array | additional options for sending the file. The following options are supported: - `mimeType`: the MIME type of the content. If not set, it will be guessed based on `$filePath` - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, meaning a download dialog will pop up. - xHeader: string, the name of the x-sendfile header. Defaults to "X-Sendfile". |
public $acceptMimeType |
public $acceptParams |
public $charset |
public $content |
public $data |
public $format |
public $formatters |
public static $httpStatuses |
public $isSent |
public $statusText |
public $stream |