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 {@link constructUrl()}. The format of the recognizable URLs is determined according to {@link 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 {@link 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 {@link 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 {@link TApplication} as the request module. It can be accessed via {@link TApplication::getRequest()}.
Since: 3.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Prado\TApplicationComponent, implements IteratorAggregate, implements ArrayAccess, implements Countable, implements Prado\IModule
Exemple #1
0
 public function testRequestWithUrlMapping()
 {
     Prado::Using('System.Web.TUrlMapping');
     $confstr = '<config><url ServiceId="testService" ServiceParameter="testServiceParam" pattern="test/{param}/?" parameters.param="\\w+"/></config>';
     $config = new TXmlDocument('1.0', 'utf8');
     $config->loadFromString($confstr);
     $module = new TUrlMapping();
     self::$app->setModule('friendly-url', $module);
     if (isset($_GET['page'])) {
         unset($_GET['page']);
     }
     // Remove service from a previous test !
     $_SERVER['REQUEST_URI'] = '/index.php/test/value2';
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['PHP_SELF'] = '/index.php/test/value2';
     $_SERVER['QUERY_STRING'] = '';
     $_SERVER['PATH_INFO'] = '/test/value2';
     $request = new THttpRequest();
     $request->setUrlManager('friendly-url');
     $request->setUrlFormat(THttpRequestUrlFormat::Path);
     $request->init(null);
     $module->init($config);
     self::assertEquals('testService', $request->resolveRequest(array('page', 'testService')));
 }