Class \Prado\Web\THttpResponse
THttpResponse implements the mechanism for sending output to client users.
To output a string to client, use write(). By default, the output is buffered until flush() is called or the application ends. The output in the buffer can also be cleaned by clear(). To disable output buffering, set BufferOutput property to false.
To send cookies to client, use getCookies(). To redirect client browser to a new URL, use redirect(). To send a file to client, use writeFile().
By default, THttpResponse is registered with TApplication as the response module. It can be accessed via TApplication::getResponse().
THttpResponse may be configured in application configuration file as follows
where \Prado\Web\getCacheExpire, \Prado\Web\getCacheControl and \Prado\Web\getBufferOutput are optional properties of THttpResponse.
THttpResponse sends charset header if either \Prado\Web\setCharset() or TGlobalization.Charset is set.
Since 3.1.2, HTTP status code can be set with the \Prado\Web\setStatusCode property.
Note: Some HTTP Status codes can require additional header or body information. So, if you use \Prado\Web\setStatusCode in your application, be sure to add theses informations. E.g : to make an http authentication :
public function clickAuth ($sender, $param)
{
$response=$this->getResponse();
$response->setStatusCode(401);
$response->appendHeader('WWW-Authenticate: Basic realm="Test"');
}
This event handler will sent the 401 status code (Unauthorized) to the browser, with the WWW-Authenticate header field. This will force the browser to ask for a username and a password.
Class hierarchy
- \Prado\Web\THttpResponse implements ITextWriter
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.0
public
|
|
public
|
addCookie(THttpCookie $cookie) : mixed
Sends a cookie.
Do not call this method directly. Operate with the result of getCookies instead. |
public
|
|
public
|
appendLog(string $message[, int $messageType = 0 ][, string $destination = '' ][, string $extraHeaders = '' ]) : mixed
Writes a log message into error log.
This method is simple wrapper of PHP function error_log. |
public
|
|
public
|
createHtmlWriter([string $type = null ]) : mixed
Creates a new instance of HTML writer.
If the type of the HTML writer is not supplied, \Prado\Web\getHtmlWriterType will be assumed. |
public
|
createNewHtmlWriter(string $type, ITextWriter $writer) : mixed
Create a new html writer instance.
This method is used internally. Please use createHtmlWriter instead. |
public
|
|
public
|
|
public
|
flushContent([bool $continueBuffering = true ]) : mixed
Outputs the buffered content, sends content-type and charset header.
This method is used internally. Please use flush instead. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getContents() : string
Returns the content in the output buffer.
The buffer will NOT be cleared after calling this method. Use clear() is you want to clear the buffer. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
httpRedirect(string $url) : mixed
Redirect the browser to another URL and exists the current application.
This method is used internally. Please use redirect instead. |
public
|
init(TXmlElement $config) : mixed
Initializes the module.
This method is required by IModule and is invoked by application. It starts output buffer if it is enabled. |
public
|
redirect(string $url) : mixed
Redirects the browser to the specified URL.
The current application will be terminated after this method is invoked. |
public
|
reload() : mixed
Reloads the current page.
The effect of this method call is the same as user pressing the refresh button on his browser (without post data). |
public
|
removeCookie(THttpCookie $cookie) : mixed
Deletes a cookie.
Do not call this method directly. Operate with the result of getCookies instead. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
setStatusCode(int $status[, null|string $reason = null ]) : mixed
Set the HTTP status code for the response.
The code and its reason will be sent to client using the currently requested http protocol version (see THttpRequest::getHttpProtocolVersion) Keep in mind that HTTP/1.0 clients might not understand all status codes from HTTP/1.1 |
public
|
write(string $str) : mixed
Outputs a string.
It may not be sent back to user immediately if output buffer is enabled. |
public
|
writeFile(string $fileName[, null|string $content = null ][, null|string $mimeType = null ][, null|array<string|int, mixed> $headers = null ][, null|bool $forceDownload = true ][, null|string $clientFileName = null ][, null|int $fileSize = null ]) : mixed
Sends a file back to user.
Make sure not to output anything else after calling this method. |
protected
|
ensureContentTypeHeaderSent() : mixed
Ensures that the HTTP header with the status code and status reason are sent
|
protected
|
ensureHttpHeaderSent() : mixed
Ensures that the HTTP header with the status code and status reason are sent
|
protected
|
|
protected
|
sendHttpHeader() : mixed
Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)
|
public
mixed
|
DEFAULT_CHARSET
|
'UTF-8'
|
public
mixed
|
DEFAULT_CONTENTTYPE
|
'text/html'
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |