- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

Packages: default System System.Caching System.Collections System.Data System.Data.ActiveRecord System.Data.ActiveRecord.Relations System.Data.ActiveRecord.Scaffold System.Data.ActiveReecord.Scaffold.InputBuilder System.Data.Commom.Sqlite System.Data.Common System.Data.Common.Mssql System.Data.Common.Mysql System.Data.Common.Oracle System.Data.Common.Pgsql System.Data.Common.Sqlite System.Data.DataGateway System.Data.SqlMap System.Data.SqlMap.Configuration System.Data.SqlMap.Statements System.Exceptions System.I18N System.IO System.Security System.Util System.Web System.Web.Services System.Web.UI System.Web.UI.ActiveControls System.Web.UI.WebControls System.Web.UI.WebControls.assets System.Xml Classes: TAssetManager TCacheHttpSession THttpCookie THttpCookieCollection THttpRequest THttpRequestUrlFormat THttpResponse THttpResponseAdapter THttpSession THttpSessionCookieMode THttpUtility TSessionIterator TUri TUrlManager TUrlMapping TUrlMappingPattern |
Keyword
# Class THttpResponse
    TComponent
       |
       --TApplicationComponent
          |
          --TModule
             |
             --THttpResponse
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(). THttpResponse may be configured in application configuration file as follows <module id="response" class="System.Web.THttpResponse" CacheExpire="20" CacheControl="nocache" BufferOutput="true" /> where CacheExpire, CacheControl and BufferOutput are optional properties of THttpResponse. THttpResponse sends charset header if either Charset or TGlobalization.Charset is set. Since 3.1.2, HTTP status code can be set with the StatusCode property. Note: Some HTTP Status codes can require additional header or body information. So, if you use 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. Since: 3.0 Author: Qiang Xue <qiang.xue@gmail.com>
Method Summary
void | addCookie ( THttpCookie $cookie) Sends a cookie.
void | appendHeader ( string $value) Sends a header.
void | appendLog ( string $message, integer $messageType, string $destination, string $extraHeaders) Writes a log message into error log.
void | clear () Clears any existing buffered content.
void | createHtmlWriter ( string $type) Creates a new instance of HTML writer.
void | createNewHtmlWriter ( string $type, ITextWriter $writer) Create a new html writer instance.
void | flush () Flush the response contents and headers.
void | flushContent () Outputs the buffered content, sends content-type and charset header.
THttpResponseAdapter | getAdapter ()
boolean | getBufferOutput ()
string | getCacheControl ()
integer | getCacheExpire ()
string | getCharset ()
string | getContents () Returns the content in the output buffer.
string | getContentType ()
THttpCookieCollection | getCookies ()
boolean | getHasAdapter ()
string | getHtmlWriterType ()
integer | getStatusCode ()
void | getStatusReason ( string 0)
void | httpRedirect ( string $url) Redirect the browser to another URL and exists the current application.
void | init ( TXmlElement $config) Initializes the module.
void | redirect ( string $url) Redirects the browser to the specified URL.
void | reload () Reloads the current page.
void | removeCookie ( THttpCookie $cookie) Deletes a cookie.
protected void | sendContentTypeHeader () Sends content type header if charset is not empty.
protected void | sendHttpHeader () Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)
void | setAdapter ( THttpResponseAdapter $adapter)
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, string $reason) Set the HTTP status code for the response.
void | write ( string $str) Outputs a string.
void | writeFile ( string $fileName, string $content, string $mimeType, array $headers, boolean $forceDownload, string $clientFileName, integer $fileSize) Sends a file back to user.
Methods Inherited From TModule
TModule::getID(), TModule::init(), TModule::setID()
Methods Inherited From TApplicationComponent
TApplicationComponent::getApplication(), TApplicationComponent::getRequest(), TApplicationComponent::getResponse(), TApplicationComponent::getService(), TApplicationComponent::getSession(), TApplicationComponent::getUser(), TApplicationComponent::publishAsset(), TApplicationComponent::publishFilePath()
Methods Inherited From TComponent
TComponent::addParsedObject(), TComponent::attachEventHandler(), TComponent::canGetProperty(), TComponent::canSetProperty(), TComponent::createdOnTemplate(), TComponent::detachEventHandler(), TComponent::evaluateExpression(), TComponent::evaluateStatements(), TComponent::getEventHandlers(), TComponent::getSubProperty(), TComponent::hasEvent(), TComponent::hasEventHandler(), TComponent::hasProperty(), TComponent::raiseEvent(), TComponent::setSubProperty(), TComponent::__get(), TComponent::__set()
Method Details
## addCookie
public void addCookie | (THttpCookie $cookie )
Sends a cookie. Do not call this method directly. Operate with the result of getCookies instead.
Input
THttpCookie | $cookie | cook to be sent
Output
Exception
## appendHeader
public void appendHeader | (string $value )
Sends a header.
Input
string | $value | header
Output
Exception
## appendLog
public void appendLog | (string $message , integer $messageType , string $destination , string $extraHeaders )
Writes a log message into error log. This method is simple wrapper of PHP function error_log.
Input
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.
Output
Exception
## clear
public void clear | ()
Clears any existing buffered content.
Output
Exception
## createHtmlWriter
public void createHtmlWriter | (string $type )
Creates a new instance of HTML writer. If the type of the HTML writer is not supplied, HtmlWriterType will be assumed.
Input
string | $type | type of the HTML writer to be created. If null, HtmlWriterType will be assumed.
Output
Exception
## createNewHtmlWriter
public void createNewHtmlWriter | (string $type , ITextWriter $writer )
Create a new html writer instance. This method is used internally. Please use createHtmlWriter instead.
Input
string | $type | type of HTML writer to be created.
ITextWriter | $writer | text writer holding the contents.
Output
Exception
## flush
public void flush | ()
Flush the response contents and headers.
Output
Exception
## flushContent
public void flushContent | ()
Outputs the buffered content, sends content-type and charset header. This method is used internally. Please use flush instead.
Output
Exception
## getAdapter
public THttpResponseAdapter getAdapter | ()
Output
THttpResponseAdapter | response adapter, null if not exist.
Exception
## getBufferOutput
public boolean getBufferOutput | ()
Output
boolean | whether to enable output buffer
Exception
## getCacheControl
public string getCacheControl | ()
Output
string | cache control method to use for session pages
Exception
## getCacheExpire
public integer getCacheExpire | ()
Output
integer | time-to-live for cached session pages in minutes, this has no effect for nocache limiter. Defaults to 180.
Exception
## getCharset
public string getCharset | ()
Output
string | output charset.
Exception
## getContents
public string getContents | ()
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.
Output
string | output that is in the buffer.
Exception
## getContentType
public string getContentType | ()
Output
string | current content type
Exception
## getCookies
public THttpCookieCollection getCookies | ()
Output
THttpCookieCollection | list of output cookies
Exception
## getHasAdapter
public boolean getHasAdapter | ()
Output
boolean | true if adapter exists, false otherwise.
Exception
## getHtmlWriterType
public string getHtmlWriterType | ()
Output
string | the type of HTML writer to be used, defaults to THtmlWriter
Exception
## getStatusCode
public integer getStatusCode | ()
Output
integer | HTTP status code, defaults to 200
Exception
## getStatusReason
public void getStatusReason | (string 0 )
Input
string | 0 | HTTP status reason
Output
Exception
## httpRedirect
public void httpRedirect | (string $url )
Redirect the browser to another URL and exists the current application. This method is used internally. Please use redirect instead.
Input
string | $url | 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.
Output
Exception
## init
public void 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.
Input
TXmlElement | $config | module configuration
Output
Exception
## redirect
public void redirect | (string $url )
Redirects the browser to the specified URL. The current application will be terminated after this method is invoked.
Input
string | $url | 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.
Output
Exception
## reload
public void 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).
Output
Exception
## removeCookie
public void removeCookie | (THttpCookie $cookie )
Deletes a cookie. Do not call this method directly. Operate with the result of getCookies instead.
Input
THttpCookie | $cookie | cook to be deleted
Output
Exception
## sendContentTypeHeader
protected void sendContentTypeHeader | ()
Sends content type header if charset is not empty.
Output
Exception
## sendHttpHeader
protected void sendHttpHeader | ()
Send the HTTP header with the status code (defaults to 200) and status reason (defaults to OK)
Output
Exception
## setAdapter
public void setAdapter | (THttpResponseAdapter $adapter )
Input
THttpResponseAdapter | $adapter | response adapter
Output
Exception
## setBufferOutput
public void setBufferOutput | (boolean $value )
Input
boolean | $value | whether to enable output buffer
Output
Exception
throws | TInvalidOperationException if session is started already
## setCacheControl
public void setCacheControl | (string $value )
Input
string | $value | cache control method to use for session pages. Valid values include none/nocache/private/private_no_expire/public
Output
Exception
## setCacheExpire
public void setCacheExpire | (integer $value )
Input
integer | $value | time-to-live for cached session pages in minutes, this has no effect for nocache limiter.
Output
Exception
## setCharset
public void setCharset | (string $charset )
Input
string | $charset | output charset.
Output
Exception
## setContentType
public string setContentType | (mixed $type )
Input
mixed | $type |
Output
string | content type, default is text/html
Exception
## setHtmlWriterType
public void setHtmlWriterType | (string $value )
Input
string | $value | the type of HTML writer to be used, may be the class name or the namespace
Output
Exception
## setStatusCode
public void setStatusCode | (integer $status , string $reason )
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
Input
integer | $status | HTTP status code
string | $reason | HTTP status reason, defaults to standard HTTP reasons
Output
Exception
## write
public void write | (string $str )
Outputs a string. It may not be sent back to user immediately if output buffer is enabled.
Input
string | $str | string to be output
Output
Exception
## writeFile
public void writeFile | (string $fileName , string $content , string $mimeType , array $headers , boolean $forceDownload , string $clientFileName , integer $fileSize )
Sends a file back to user. Make sure not to output anything else after calling this method.
Input
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. Each array element represents a header string (e.g. 'Content-Type: text/plain').
boolean | $forceDownload | force download of file, even if browser able to display inline. Defaults to 'true'.
string | $clientFileName | force a specific file name on client side. Defaults to 'null' means auto-detect.
integer | $fileSize | size of file or content in bytes if already known. Defaults to 'null' means auto-detect.
Output
Exception
throws | TInvalidDataValueException if the file cannot be found