Class THttpResponse

Description

Implements interfaces:

THttpResponse class

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

THttpRequest may be configured in application configuration file as follows <module id="response" CacheExpire="20" CacheControl="nocache" BufferOutput="true" /> where CacheExpire, CacheControl and BufferOutput are configurable properties of THttpResponse.

When sending headers the Charset set in TGlobalization::getCharset() is use when Charset is null or empty in THttpResponse.

Located in /Web/THttpResponse.php (line 43)

TComponent
   |
   --TApplicationComponent
      |
      --TModule
         |
         --THttpResponse
Method Summary
void __destruct ()
void addCookie (THttpCookie $cookie)
void appendHeader (string $value)
void appendLog (string $message, integer $messageType, [string $destination = ''], [string $extraHeaders = ''])
void clear ()
void createHtmlWriter ([string $type = null])
void flush ()
boolean getBufferOutput ()
string getCacheControl ()
integer getCacheExpire ()
string getCharset ()
string getContents ()
string getContentType ()
string getHtmlWriterType ()
integer getStatusCode ()
void init (TXmlElement $config)
void redirect (string $url)
void reload ()
void removeCookie (THttpCookie $cookie)
void setBufferOutput (boolean $value)
void setCacheControl (string $value)
void setCacheExpire (integer $value)
void setCharset (string $charset)
string setContentType (mixed $type)
void setHtmlWriterType (string $value)
void setStatusCode (integer $status)
void write (string $str)
void writeFile (string $fileName, [string $content = null], [string $mimeType = null], [array $headers = null])
Methods
Destructor __destruct (line 78)

Destructor.

Flushes any existing content in buffer.

  • access: public
void __destruct ()
addCookie (line 376)

Sends a cookie.

Do not call this method directly. Operate with the result of getCookies instead.

  • access: public
void addCookie (THttpCookie $cookie)
appendHeader (line 351)

Sends a header.

  • access: public
void appendHeader (string $value)
  • string $value: header
appendLog (line 366)

Writes a log message into error log.

This method is simple wrapper of PHP function error_log.

void appendLog (string $message, integer $messageType, [string $destination = ''], [string $extraHeaders = ''])
  • string $message: The error message that should be logged
  • integer $messageType: where the error should go
  • string $destination: The destination. Its meaning depends on the message parameter as described above
  • string $extraHeaders: 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.
clear (line 340)

Clears any existing buffered content.

  • access: public
void clear ()
createHtmlWriter (line 419)

Creates a new instance of HTML writer.

If the type of the HTML writer is not supplied, HtmlWriterType will be assumed.

  • access: public
void createHtmlWriter ([string $type = null])
  • string $type: type of the HTML writer to be created. If null, HtmlWriterType will be assumed.
flush (line 300)

Outputs the buffered content, sends content-type and charset header.

  • access: public
void flush ()
getBufferOutput (line 166)
  • return: whether to enable output buffer
  • access: public
boolean getBufferOutput ()
getCacheControl (line 117)
  • return: cache control method to use for session pages
  • access: public
string getCacheControl ()
getCacheExpire (line 101)
  • return: time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180.
  • access: public
integer getCacheExpire ()
getCharset (line 150)
  • return: output charset.
  • access: public
string getCharset ()
getContents (line 331)

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.

  • return: output that is in the buffer.
  • access: public
string getContents ()
getContentType (line 142)
  • return: current content type
  • access: public
string getContentType ()
getCookies (line 202)
  • return: list of output cookies
  • access: public
THttpCookieCollection getCookies ()
getHtmlWriterType (line 401)
  • return: the type of HTML writer to be used, defaults to THtmlWriter
  • access: public
string getHtmlWriterType ()
getStatusCode (line 186)
  • return: HTTP status code, defaults to 200
  • access: public
integer getStatusCode ()
init (line 90)

Initializes the module.

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

  • access: public
void init (TXmlElement $config)

Redefinition of:
TModule::init()
Initializes the module.
redirect (line 279)

Redirects the browser to the specified URL.

The current application will be terminated after this method is invoked.

  • access: public
void redirect (string $url)
  • string $url: URL to be redirected to
reload (line 292)

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

  • access: public
void reload ()
removeCookie (line 393)

Deletes a cookie.

Do not call this method directly. Operate with the result of getCookies instead.

  • access: public
void removeCookie (THttpCookie $cookie)
sendContentTypeHeader (line 311)

Sends content type header if charset is not empty.

  • access: protected
void sendContentTypeHeader ()
setBufferOutput (line 175)
  • access: public
  • throws: TInvalidOperationException if session is started already
void setBufferOutput (boolean $value)
  • boolean $value: whether to enable output buffer
setCacheControl (line 126)
  • access: public
void setCacheControl (string $value)
  • string $value: cache control method to use for session pages. Valid values include none/nocache/private/private_no_expire/public
setCacheExpire (line 109)
  • access: public
void setCacheExpire (integer $value)
  • integer $value: time-to-live for cached session pages in minutes, this has no effect for nocache limiter.
setCharset (line 158)
  • access: public
void setCharset (string $charset)
  • string $charset: output charset.
setContentType (line 134)
  • return: content type, default is text/html
  • access: public
string setContentType (mixed $type)
setHtmlWriterType (line 409)
  • access: public
void setHtmlWriterType (string $value)
  • string $value: the type of HTML writer to be used, may be the class name or the namespace
setStatusCode (line 194)
  • access: public
void setStatusCode (integer $status)
  • integer $status: HTTP status code
write (line 214)

Outputs a string.

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

  • access: public
void write (string $str)
  • string $str: string to be output
writeFile (line 228)

Sends a file back to user.

Make sure not to output anything else after calling this method.

  • access: public
  • throws: TInvalidDataValueException if the file cannot be found
void writeFile (string $fileName, [string $content = null], [string $mimeType = null], [array $headers = null])
  • string $fileName: file name
  • string $content: content to be set. If null, the content will be read from the server file pointed to by $fileName.
  • string $mimeType: mime type of the content.
  • array $headers: list of headers to be sent

Inherited Methods

Inherited From TModule

TModule::getID()
TModule::init()
TModule::setID()

Inherited From TApplicationComponent

TApplicationComponent::getApplication()
TApplicationComponent::getRequest()
TApplicationComponent::getResponse()
TApplicationComponent::getService()
TApplicationComponent::getSession()
TApplicationComponent::getUser()
TApplicationComponent::publishAsset()
TApplicationComponent::publishFilePath()

Inherited From TComponent

TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__get()
TComponent::__set()

Documentation generated on Sun, 04 Jun 2006 18:59:31 -0400 by phpDocumentor 1.3.0RC4