Class \Prado\Web\THttpRequest
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 \Prado\Web\setUrlManager. 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 \Prado\Web\setUrlFormat. 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 \Prado\Web\setUrlManager.
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().
Class hierarchy
- \Prado\Web\THttpRequest implements IteratorAggregate, ArrayAccess, Countable, IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.0
public
|
add(mixed $key, mixed $value) : mixed
Adds an item into the request.
Note, if the specified key already exists, the old value will be overwritten. |
public
|
|
public
|
constructUrl(string $serviceID, string $serviceParam[, null|array<string|int, mixed> $getItems = null ][, bool $encodeAmpersand = true ][, bool $encodeGetItems = true ]) : string
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 \Prado\Web\setUrlManager 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 \Prado\Web\getBaseUrl. |
public
|
|
public
|
count() : int
Returns the number of items in the request.
This method is required by \Countable interface. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getIterator() : Iterator
Returns an iterator for traversing the items in the list.
This method is required by the interface \IteratorAggregate. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getUserLanguages() : array<string|int, mixed>
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
|
init(TXmlElement $config) : mixed
Initializes the module.
This method is required by IModule and is invoked by application. |
public
|
itemAt(mixed $key) : mixed
Returns the item with the specified key.
This method is exactly the same as offsetGet. |
public
|
offsetExists(mixed $offset) : bool
Returns whether there is an element at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetGet(int $offset) : mixed
Returns the element at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetSet(int $offset, mixed $item) : void
Sets the element at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
offsetUnset(mixed $offset) : void
Unsets the element at the specified offset.
This method is required by the interface \ArrayAccess. |
public
|
onResolveRequest(array<string|int, mixed> $serviceIDs, array<string|int, mixed> $urlParams) : array<string|int, mixed>|false|string
Raised when resolving the request. This is for application specific request
resolution. Event Handlers can return `false` for no service, a `string` of the
service id to use, or an array replacing the $urlParams. By returning null,
the result is skipped and has no effect. Event Handler results are stacked and
results are popped until a valid result is found. The only invalid result is
if a string is provided that is not in the $serviceIDs.
The lower priorities of event handlers are more important and so should be last. |
public
|
|
public
|
resolveRequest(array<string|int, mixed> $serviceIDs) : string
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. Attach an event handler on onResolveRequest to provide your own service resolution. |
public
|
setCgiFix(int $value) : mixed
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
|
setEnableCache(bool $value) : mixed
Set true to cache the UrlManager instance. Consider to enable this cache
when the application defines a lot of TUrlMappingPatterns
|
public
|
|
public
|
|
public
|
setResolveMethod(THttpRequestResolveMethod $value) : mixed
Sets the method used to determine the service used to handle the request.
This can be done using the service order defined in application.xml or the order of the parameters received in the request. |
public
|
|
public
|
|
public
|
setUrlFormat(THttpRequestUrlFormat $value) : mixed
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. |
public
|
setUrlManager(string $value) : mixed
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. |
public
|
|
public
deprecated
|
stripSlashes(mixed &$data) : mixed
Strips slashes from input data.
This method is applied when magic quotes is enabled. |
public
|
|
protected
|
|
protected
|
|
protected
|
|
protected
|
parseUrl() : array<string|int, mixed>
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
mixed
|
CGIFIX__PATH_INFO
|
1
|
public
mixed
|
CGIFIX__SCRIPT_NAME
|
2
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |