PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class THttpResponse

THttpResponse class

THttpResponse implements the mechanism for sending output to client users.

To output a string to client, use THttpResponse::write(). By default, the output is buffered until THttpResponse::flush() is called or the application ends. The output in the buffer can also be cleaned by THttpResponse::clear(). To disable output buffering, set BufferOutput property to false.

To send cookies to client, use THttpResponse::getCookies(). To redirect client browser to a new URL, use THttpResponse::redirect(). To send a file to client, use THttpResponse::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

<module id="response" class="System.Web.THttpResponse" CacheExpire="20" CacheControl="nocache" BufferOutput="true" />

where getCacheExpire CacheExpire, getCacheControl CacheControl and getBufferOutput BufferOutput are optional properties of THttpResponse.

THttpResponse sends charset header if either setCharset() Charset or TGlobalization::setCharset() TGlobalization.Charset is set.

Since 3.1.2, HTTP status code can be set with the setStatusCode StatusCode property.

Note: Some HTTP Status codes can require additional header or body information. So, if you use setStatusCode StatusCode 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.

TComponent
Extended by TApplicationComponent
Extended by TModule implements IModule
Extended by THttpResponse implements ITextWriter
Package: System\Web
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Web/THttpResponse.php
Methods summary
public
# __destruct( )

Destructor. Flushes any existing content in buffer.

Destructor. Flushes any existing content in buffer.

Overrides

TComponent::__destruct()
public
# setAdapter( THttpResponseAdapter $adapter )

Parameters

$adapter
THttpResponseAdapter
response adapter
public THttpResponseAdapter
# getAdapter( )

Returns

THttpResponseAdapter
response adapter, null if not exist.
public boolean
# getHasAdapter( )

Returns

boolean
true if adapter exists, false otherwise.
public
# init( TXmlElement $config )

Initializes the module. This method is required by IModule and is invoked by application. It starts output buffer if it is enabled.

Initializes the module. This method is required by IModule and is invoked by application. It starts output buffer if it is enabled.

Parameters

$config
TXmlElement
module configuration

Overrides

TModule::init()
public integer
# getCacheExpire( )

Returns

integer
time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180.
public
# setCacheExpire( integer $value )

Parameters

$value
integer
time-to-live for cached session pages in minutes, this has no effect for nocache limiter.
public string
# getCacheControl( )

Returns

string
cache control method to use for session pages
public
# setCacheControl( string $value )

Parameters

$value
string
cache control method to use for session pages. Valid values include none/nocache/private/private_no_expire/public
public string
# setContentType( mixed $type )

Returns

string
content type, default is text/html
public string
# getContentType( )

Returns

string
current content type
public string|boolean
# getCharset( )

Returns

string|boolean
output charset.
public
# setCharset( string|boolean $charset )

Parameters

$charset
string|boolean
output charset.
public boolean
# getBufferOutput( )

Returns

boolean
whether to enable output buffer
public
# setBufferOutput( boolean $value )

Parameters

$value
boolean
whether to enable output buffer

Throws

TInvalidOperationException
if session is started already
public integer
# getStatusCode( )

Returns

integer
HTTP status code, defaults to 200
public
# setStatusCode( integer $status, string $reason = null )

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

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

Parameters

$status
integer
HTTP status code
$reason
string
HTTP status reason, defaults to standard HTTP reasons
public
# getStatusReason( )
public THttpCookieCollection
# getCookies( )

Returns

THttpCookieCollection
list of output cookies
public
# write( string $str )

Outputs a string. It may not be sent back to user immediately if output buffer is enabled.

Outputs a string. It may not be sent back to user immediately if output buffer is enabled.

Parameters

$str
string
string to be output

Implementation of

ITextWriter::write()
public
# writeFile( string $fileName, string $content = null, string $mimeType = null, array $headers = null, boolean $forceDownload = true, string $clientFileName = null, integer $fileSize = null )

Sends a file back to user. Make sure not to output anything else after calling this method.

Sends a file back to user. Make sure not to output anything else after calling this method.

Parameters

$fileName
string
file name
$content
string
content to be set. If null, the content will be read from the server file pointed to by $fileName.
$mimeType
string
mime type of the content.
$headers
array
list of headers to be sent. Each array element represents a header string (e.g. 'Content-Type: text/plain').
$forceDownload
boolean
force download of file, even if browser able to display inline. Defaults to 'true'.
$clientFileName
string
force a specific file name on client side. Defaults to 'null' means auto-detect.
$fileSize
integer
size of file or content in bytes if already known. Defaults to 'null' means auto-detect.

Throws

TInvalidDataValueException
if the file cannot be found
public
# redirect( string $url )

Redirects the browser to the specified URL. The current application will be terminated after this method is invoked.

Redirects the browser to the specified URL. The current application will be terminated after this method is invoked.

Parameters

$url
string
URL to be redirected to. If the URL is a relative one, the base URL of the current request will be inserted at the beginning.
public
# httpRedirect( string $url )

Redirect the browser to another URL and exists the current application. This method is used internally. Please use THttpResponse::redirect() instead.

Redirect the browser to another URL and exists the current application. This method is used internally. Please use THttpResponse::redirect() instead.

Parameters

$url
string
URL to be redirected to. If the URL is a relative one, the base URL of the current request will be inserted at the beginning.

Since

3.1.5 You can set the set setStatusCode StatusCode to a value between 300 and 399 before calling this function to change the type of redirection. If not specified, StatusCode will be 302 (Found) by default
public
# reload( )

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).

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
# flush( mixed $continueBuffering = true )

Flush the response contents and headers.

Flush the response contents and headers.

Implementation of

ITextWriter::flush()
public
# ensureHeadersSent( )

Ensures that HTTP response and content-type headers are sent

Ensures that HTTP response and content-type headers are sent

public
# flushContent( boolean $continueBuffering = true )

Outputs the buffered content, sends content-type and charset header. This method is used internally. Please use THttpResponse::flush() instead.

Outputs the buffered content, sends content-type and charset header. This method is used internally. Please use THttpResponse::flush() instead.

Parameters

$continueBuffering
boolean
whether to continue buffering after flush if buffering was active
protected
# ensureHttpHeaderSent( )

Ensures that the HTTP header with the status code and status reason are sent

Ensures that the HTTP header with the status code and status reason are sent

protected
# sendHttpHeader( )

Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)

Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)

protected
# ensureContentTypeHeaderSent( )

Ensures that the HTTP header with the status code and status reason are sent

Ensures that the HTTP header with the status code and status reason are sent

protected
# sendContentTypeHeader( )

Sends content type header with optional charset.

Sends content type header with optional charset.

public string
# getContents( )

Returns the content in the output buffer. The buffer will NOT be cleared after calling this method. Use THttpResponse::clear() is you want to clear the buffer.

Returns the content in the output buffer. The buffer will NOT be cleared after calling this method. Use THttpResponse::clear() is you want to clear the buffer.

Returns

string
output that is in the buffer.
public
# clear( )

Clears any existing buffered content.

Clears any existing buffered content.

public array
# getHeaders( integer|null $case = null )

Parameters

$case
integer|null
Either CASE_UPPER or CASE_LOWER or as is null (default)

Returns

array
public
# appendHeader( string $value, boolean $replace = true )

Sends a header.

Sends a header.

Parameters

$value
string
header
$replace
boolean
whether the header should replace a previous similar header, or add a second header of the same type
public
# appendLog( string $message, integer $messageType = 0, string $destination = '', string $extraHeaders = '' )

Writes a log message into error log. This method is simple wrapper of PHP function error_log.

Writes a log message into error log. This method is simple wrapper of PHP function error_log.

Parameters

$message
string
The error message that should be logged
$messageType
integer
where the error should go
$destination
string
The destination. Its meaning depends on the message parameter as described above
$extraHeaders
string
The extra headers. It's used when the message parameter is set to 1. This message type uses the same internal function as mail() does.

See

http://us2.php.net/manual/en/function.error-log.php
public
# addCookie( THttpCookie $cookie )

Sends a cookie. Do not call this method directly. Operate with the result of THttpResponse::getCookies() instead.

Sends a cookie. Do not call this method directly. Operate with the result of THttpResponse::getCookies() instead.

Parameters

$cookie
THttpCookie
cook to be sent
public
# removeCookie( THttpCookie $cookie )

Deletes a cookie. Do not call this method directly. Operate with the result of THttpResponse::getCookies() instead.

Deletes a cookie. Do not call this method directly. Operate with the result of THttpResponse::getCookies() instead.

Parameters

$cookie
THttpCookie
cook to be deleted
public string
# getHtmlWriterType( )

Returns

string
the type of HTML writer to be used, defaults to THtmlWriter
public
# setHtmlWriterType( string $value )

Parameters

$value
string
the type of HTML writer to be used, may be the class name or the namespace
public
# createHtmlWriter( string $type = null )

Creates a new instance of HTML writer. If the type of the HTML writer is not supplied, getHtmlWriterType HtmlWriterType will be assumed.

Creates a new instance of HTML writer. If the type of the HTML writer is not supplied, getHtmlWriterType HtmlWriterType will be assumed.

Parameters

$type
string
type of the HTML writer to be created. If null, getHtmlWriterType HtmlWriterType will be assumed.
public
# createNewHtmlWriter( string $type, ITextWriter $writer )

Create a new html writer instance. This method is used internally. Please use THttpResponse::createHtmlWriter() instead.

Create a new html writer instance. This method is used internally. Please use THttpResponse::createHtmlWriter() instead.

Parameters

$type
string
type of HTML writer to be created.
$writer
ITextWriter
text writer holding the contents.
Methods inherited from TModule
getID(), setID()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __construct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants summary
string DEFAULT_CONTENTTYPE 'text/html'
#
string DEFAULT_CHARSET 'UTF-8'
#
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO