- 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 THttpRequest
    TComponent
       |
       --TApplicationComponent
          |
          --THttpRequest
THttpRequest class THttpRequest provides storage and access scheme for user request sent via HTTP. It also encapsulates a uniform way to parse and construct URLs. User post data can be retrieved from THttpRequest by using it like an associative array. For example, to test if a user supplies a variable named 'param1', you can use,

       if(isset($request['param1'])) ...
       // equivalent to:
       // if($request->contains('param1')) ...
To get the value of 'param1', use,

       $value=$request['param1'];
       // equivalent to:
       //   $value=$request->itemAt('param1');
To traverse the user post data, use

       foreach($request as $name=>$value) ...
Note, POST and GET variables are merged together in THttpRequest. If a variable name appears in both POST and GET data, then POST data takes precedence. To construct a URL that can be recognized by Prado, use constructUrl(). The format of the recognizable URLs is determined according to UrlManager. By default, the following two formats are recognized:

     /index.php?ServiceID=ServiceParameter&Name1=Value1&Name2=Value2
     /index.php/ServiceID,ServiceParameter/Name1,Value1/Name2,Value2
The first format is called 'Get' while the second 'Path', which is specified via UrlFormat. For advanced users who want to use their own URL formats, they can write customized URL management modules and install the managers as application modules and set UrlManager. The ServiceID in the above URLs is as defined in the application configuration (e.g. the default page service's service ID is 'page'). As a consequence, your GET variable names should not conflict with the service IDs that your application supports. THttpRequest also provides the cookies sent by the user, user information such as his browser capabilities, accepted languages, etc. By default, THttpRequest is registered with TApplication as the request module. It can be accessed via TApplication::getRequest(). Since: 3.0 Author: Qiang Xue <qiang.xue@gmail.com>
Method Summary
void | add ( mixed $key, mixed $value) Adds an item into the request.
void | clear () Removes all items in the request.
string | constructUrl ( string $serviceID, string $serviceParam, array $getItems, boolean $encodeAmpersand, boolean $encodeGetItems) Constructs a URL that can be recognized by PRADO.
boolean | contains ( mixed $key)
integer | count () Returns the number of items in the request.
string | getAbsoluteApplicationUrl ( boolean $forceSecureConnection)
string | getAcceptTypes ()
string | getApplicationFilePath ()
string | getApplicationUrl ()
string | getBaseUrl ( boolean $forceSecureConnection)
array | getBrowser ()
THttpCookieCollection | getCookies ()
integer | getCount ()
boolean | getEnableCookieValidation ()
array | getEnvironmentVariables ()
string | getHttpProtocolVersion ()
string | getID ()
boolean | getIsSecureConnection ()
Iterator | getIterator () Returns an iterator for traversing the items in the list.
array | getKeys ()
string | getPathInfo ()
string | getQueryString ()
boolean | getRequestResolved ()
string | getRequestType ()
string | getRequestUri ()
string | getServerName ()
integer | getServerPort ()
array | getServerVariables ()
string | getServiceID ()
string | getServiceParameter ()
array | getUploadedFiles ()
TUri | getUrl ()
THttpRequestUrlFormat | getUrlFormat ()
string | getUrlManager ()
TUrlManager | getUrlManagerModule ()
string | getUrlParamSeparator ()
string | getUrlReferrer ()
string | getUserAgent ()
string | getUserHost ()
string | getUserHostAddress ()
array | getUserLanguages () Returns a list of user preferred languages.
void | init ( TXmlElement $config) Initializes the module.
mixed | itemAt ( mixed $key) Returns the item with the specified key.
boolean | offsetExists ( mixed $offset) Returns whether there is an element at the specified offset.
mixed | offsetGet ( integer $offset) Returns the element at the specified offset.
void | offsetSet ( integer $offset, mixed $item) Sets the element at the specified offset.
void | offsetUnset ( mixed $offset) Unsets the element at the specified offset.
protected array | parseUrl () Parses the request URL and returns an array of input parameters (excluding GET variables).
mixed | remove ( mixed $key) Removes an item from the request by its key.
string | resolveRequest ( array $serviceIDs) Resolves the requested service.
void | setEnableCookieValidation ( boolean $value)
void | setID ( string $value)
void | setServiceID ( string $value) Sets the requested service ID.
void | setServiceParameter ( string $value) Sets the requested service parameter.
void | setUrlFormat ( THttpRequestUrlFormat $value) Sets the format of URLs constructed and interpretted by the request module.
void | setUrlManager ( string $value) Sets the URL manager module.
void | setUrlParamSeparator ( string $value)
mixed | stripSlashes ( mixed &$data) Strips slashes from input data.
array | toArray ()
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
## add
public void add | (mixed $key , mixed $value )
Adds an item into the request. Note, if the specified key already exists, the old value will be overwritten.
Input
mixed | $key | key
mixed | $value | value
Output
Exception
## clear
public void clear | ()
Removes all items in the request.
Output
Exception
## constructUrl
public string constructUrl | (string $serviceID , string $serviceParam , array $getItems , boolean $encodeAmpersand , boolean $encodeGetItems )
Constructs a URL that can be recognized by PRADO. The actual construction work is done by the URL manager module. This method may append session information to the generated URL if needed. You may provide your own URL manager module by setting UrlManager to provide your own URL scheme. Note, the constructed URL does not contain the protocol and hostname part. You may obtain an absolute URL by prepending the constructed URL with BaseUrl.
Input
string | $serviceID | service ID
string | $serviceParam | service parameter
array | $getItems | GET parameters, null if not needed
boolean | $encodeAmpersand | whether to encode the ampersand in URL, defaults to true.
boolean | $encodeGetItems | whether to encode the GET parameters (their names and values), defaults to false.
Output
string | URL
Exception
## contains
public boolean contains | (mixed $key )
Input
mixed | $key | the key
Output
boolean | whether the request contains an item with the specified key
Exception
## count
public integer count | ()
Returns the number of items in the request. This method is required by Countable interface.
Output
integer | number of items in the request.
Exception
## getAbsoluteApplicationUrl
public string getAbsoluteApplicationUrl | (boolean $forceSecureConnection )
Input
boolean | $forceSecureConnection | whether to use HTTPS instead of HTTP even if the current request is sent via HTTP
Output
string | entry script URL (w/ host part)
Exception
## getAcceptTypes
public string getAcceptTypes | ()
Output
string | user browser accept types
Exception
## getApplicationFilePath
public string getApplicationFilePath | ()
Output
string | application entry script file path (processed w/ realpath())
Exception
## getApplicationUrl
public string getApplicationUrl | ()
Output
string | entry script URL (w/o host part)
Exception
## getBaseUrl
public string getBaseUrl | (boolean $forceSecureConnection )
Input
boolean | $forceSecureConnection | whether to use HTTPS instead of HTTP even if the current request is sent via HTTP
Output
string | schema and hostname of the requested URL
Exception
## getBrowser
public array getBrowser | ()
Output
array | user browser capabilities
Exception
## getCookies
public THttpCookieCollection getCookies | ()
Output
THttpCookieCollection | list of cookies to be sent
Exception
## getCount
public integer getCount | ()
Output
integer | the number of items in the request
Exception
## getEnableCookieValidation
public boolean getEnableCookieValidation | ()
Output
boolean | whether cookies should be validated. Defaults to false.
Exception
## getEnvironmentVariables
public array getEnvironmentVariables | ()
Output
array | list of environment variables.
Exception
## getHttpProtocolVersion
public string getHttpProtocolVersion | ()
Output
string | the requested http procolol. Blank string if not defined.
Exception
## getID
public string getID | ()
Output
string | id of this module
Exception
## getIsSecureConnection
public boolean getIsSecureConnection | ()
Output
boolean | if the request is sent via secure channel (https)
Exception
## getIterator
public Iterator getIterator | ()
Returns an iterator for traversing the items in the list. This method is required by the interface IteratorAggregate.
Output
Iterator | an iterator for traversing the items in the list.
Exception
## getKeys
public array getKeys | ()
Output
array | the key list
Exception
## getPathInfo
public string getPathInfo | ()
Output
string | part of the request URL after script name and before question mark.
Exception
## getQueryString
public string getQueryString | ()
Output
string | part of that request URL after the question mark
Exception
## getRequestResolved
public boolean getRequestResolved | ()
Output
boolean | true if request is already resolved, false otherwise.
Exception
## getRequestType
public string getRequestType | ()
Output
string | request type, can be GET, POST, HEAD, or PUT
Exception
## getRequestUri
public string getRequestUri | ()
Output
string | part of that request URL after the host info (including pathinfo and query string)
Exception
## getServerName
public string getServerName | ()
Output
string | server name
Exception
## getServerPort
public integer getServerPort | ()
Output
integer | server port number
Exception
## getServerVariables
public array getServerVariables | ()
Output
array | list of server variables.
Exception
## getServiceID
public string getServiceID | ()
Output
string | requested service ID
Exception
## getServiceParameter
public string getServiceParameter | ()
Output
string | requested service parameter
Exception
## getUploadedFiles
public array getUploadedFiles | ()
Output
array | list of uploaded files.
Exception
## getUrl
public TUri getUrl | ()
Output
TUri | the request URL
Exception
## getUrlFormat
public THttpRequestUrlFormat getUrlFormat | ()
Output
THttpRequestUrlFormat | the format of URLs. Defaults to THttpRequestUrlFormat::Get.
Exception
## getUrlManager
public string getUrlManager | ()
Output
string | the ID of the URL manager module
Exception
## getUrlManagerModule
public TUrlManager getUrlManagerModule | ()
Output
TUrlManager | the URL manager module
Exception
## getUrlParamSeparator
public string getUrlParamSeparator | ()
Output
string | separator used to separate GET variable name and value when URL format is Path. Defaults to comma ','.
Exception
## getUrlReferrer
public string getUrlReferrer | ()
Output
string | URL referrer, null if not present
Exception
## getUserAgent
public string getUserAgent | ()
Output
string | user agent
Exception
## getUserHost
public string getUserHost | ()
Output
string | user host name, null if cannot be determined
Exception
## getUserHostAddress
public string getUserHostAddress | ()
Output
string | user IP address
Exception
## getUserLanguages
public array getUserLanguages | ()
Returns a list of user preferred languages. The languages are returned as an array. Each array element represents a single language preference. The languages are ordered according to user preferences. The first language is the most preferred.
Output
array | list of user preferred languages.
Exception
## init
public void init | (TXmlElement $config )
Initializes the module. This method is required by IModule and is invoked by application.
Input
TXmlElement | $config | module configuration
Output
Exception
## itemAt
public mixed itemAt | (mixed $key )
Returns the item with the specified key. This method is exactly the same as offsetGet.
Input
mixed | $key | the key
Output
mixed | the element at the offset, null if no element is found at the offset
Exception
## offsetExists
public boolean offsetExists | (mixed $offset )
Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess.
Input
mixed | $offset | the offset to check on
Output
Exception
## offsetGet
public mixed offsetGet | (integer $offset )
Returns the element at the specified offset. This method is required by the interface ArrayAccess.
Input
integer | $offset | the offset to retrieve element.
Output
mixed | the element at the offset, null if no element is found at the offset
Exception
## offsetSet
public void offsetSet | (integer $offset , mixed $item )
Sets the element at the specified offset. This method is required by the interface ArrayAccess.
Input
integer | $offset | the offset to set element
mixed | $item | the element value
Output
Exception
## offsetUnset
public void offsetUnset | (mixed $offset )
Unsets the element at the specified offset. This method is required by the interface ArrayAccess.
Input
mixed | $offset | the offset to unset element
Output
Exception
## parseUrl
protected array parseUrl | ()
Parses the request URL and returns an array of input parameters (excluding GET variables). You may override this method to support customized URL format.
Output
array | list of input parameters, indexed by parameter names
Exception
## remove
public mixed remove | (mixed $key )
Removes an item from the request by its key.
Input
mixed | $key | the key of the item to be removed
Output
mixed | the removed value, null if no such key exists.
Exception
throws | TInvalidOperationException if the item cannot be removed
## resolveRequest
public string resolveRequest | (array $serviceIDs )
Resolves the requested service. This method implements a URL-based service resolution. A URL in the format of /index.php?sp=serviceID.serviceParameter will be resolved with the serviceID and the serviceParameter. You may override this method to provide your own way of service resolution.
Input
array | $serviceIDs | list of valid service IDs
Output
string | the currently requested service ID, null if no service ID is found
Exception
## setEnableCookieValidation
public void setEnableCookieValidation | (boolean $value )
Input
boolean | $value | whether cookies should be validated.
Output
Exception
## setID
public void setID | (string $value )
Input
string | $value | id of this module
Output
Exception
## setServiceID
public void setServiceID | (string $value )
Sets the requested service ID.
Input
string | $value | requested service ID
Output
Exception
## setServiceParameter
public void setServiceParameter | (string $value )
Sets the requested service parameter.
Input
string | $value | requested service parameter
Output
Exception
## setUrlFormat
public void setUrlFormat | (THttpRequestUrlFormat $value )
Sets the format of URLs constructed and interpretted by the request module. A Get URL format is like index.php?name1=value1&name2=value2 while a Path URL format is like index.php/name1,value1/name2,value. Changing the UrlFormat will affect constructUrl and how GET variables are parsed.
Input
THttpRequestUrlFormat | $value | the format of URLs.
Output
Exception
## setUrlManager
public void setUrlManager | (string $value )
Sets the URL manager module. By default, TUrlManager is used for managing URLs. You may specify a different module for URL managing tasks by loading it as an application module and setting this property with the module ID.
Input
string | $value | the ID of the URL manager module
Output
Exception
## setUrlParamSeparator
public void setUrlParamSeparator | (string $value )
Input
string | $value | separator used to separate GET variable name and value when URL format is Path.
Output
Exception
throws | TInvalidDataValueException if the separator is not a single character
## stripSlashes
public mixed stripSlashes | (mixed &$data )
Strips slashes from input data. This method is applied when magic quotes is enabled.
Input
mixed | &$data | input data to be processed
Output
mixed | processed data
Exception
## toArray
public array toArray | ()
Output
array | the list of items in array
Exception