Class 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 THttpRequest::constructUrl()
. The format of the recognizable URLs is determined according to
setUrlManager 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 setUrlFormat 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 setUrlManager 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()
.
- TComponent
-
TApplicationComponent
-
THttpRequest implements IteratorAggregate, ArrayAccess, Countable, IModule
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Web/THttpRequest.php
public
string
|
|
public
|
|
public
|
#
init(
Initializes the module. This method is required by IModule and is invoked by application. |
public
mixed
|
#
stripSlashes( mixed & $data )
Strips slashes from input data. This method is applied when magic quotes is enabled. |
public
|
|
public
|
#
setEnableCache( boolean $value )
Set true to cache the UrlManager instance. Consider to enable this cache when the application defines a lot of TUrlMappingPatterns |
public
boolean
|
|
protected
|
|
protected
boolean
|
|
protected
|
|
public
string
|
|
public
|
#
setUrlManager( string $value )
Sets the URL manager module. By default, |
public
|
|
public
|
|
public
|
#
setUrlFormat(
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 |
public
string
|
|
public
|
|
public
string
|
|
public
string
|
|
public
boolean
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
array
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
integer
|
|
public
string
|
|
public
array
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
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. |
public
boolean
|
|
public
|
|
public
integer
|
|
public
|
#
setCgiFix( integer $value )
Enable this, if you're using PHP via CGI with php.ini setting "cgi.fix_pathinfo=1" and have trouble with friendly URL feature. Enable this only if you really know what you are doing! |
public
|
|
public
array
|
|
public
array
|
|
public
array
|
|
public
string
|
#
constructUrl( string $serviceID, string $serviceParam, array $getItems = null, boolean $encodeAmpersand = true, boolean $encodeGetItems = true )
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 setUrlManager UrlManager to provide your own URL scheme. |
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. |
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. |
public
boolean
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
Iterator
|
#
getIterator( )
Returns an iterator for traversing the items in the list. This method is required by the interface IteratorAggregate. |
public
integer
|
|
public
integer
|
#
count( )
Returns the number of items in the request. This method is required by Countable interface. |
public
array
|
|
public
mixed
|
#
itemAt( mixed $key )
Returns the item with the specified key. This method is exactly the same as
|
public
|
#
add( mixed $key, mixed $value )
Adds an item into the request. Note, if the specified key already exists, the old value will be overwritten. |
public
mixed
|
|
public
|
|
public
boolean
|
|
public
array
|
|
public
boolean
|
#
offsetExists( mixed $offset )
Returns whether there is an element at the specified offset. This method is required by the interface ArrayAccess. |
public
mixed
|
#
offsetGet( integer $offset )
Returns the element at the specified offset. This method is required by the interface ArrayAccess. |
public
|
#
offsetSet( integer $offset, mixed $item )
Sets the element at the specified offset. This method is required by the interface ArrayAccess. |
public
|
#
offsetUnset( mixed $offset )
Unsets the element at the specified offset. This method is required by the interface ArrayAccess. |
getApplication(),
getRequest(),
getResponse(),
getService(),
getSession(),
getUser(),
publishAsset(),
publishFilePath()
|
integer |
CGIFIX__PATH_INFO |
1 |
|
integer |
CGIFIX__SCRIPT_NAME |
2 |
GLOBAL_RAISE_EVENT_LISTENER
|