ActiveWAFL controller actions all receive an instance of an HTTP Request object as an attribute.
This object provides methods for getting information about the request, including any GET/POST variables submitted via a form or the URL.
There are several strongly-typed methods for getting the request variables. These methods all begin with
For example, there is
GetInputBoolean, and so on.
There is one method,
GetInputArray, for getting arrays of input, for example if you submit several form elements with the same name followed by square brackets. There is also a generic method named
GetInput which does not validate the data type of the input.
Example of Reading Input in a Controller Action
- namespace MyApp\Controllers;
- class MyController
- extends \DblEj\Mvc\ControllerBase
- public function DefaultAction(\DblEj\Communication\Http\Request $request, \DblEj\Application\IMvcWebApplication $app)
- //read the value of the Foos from the request input, validating that its an integer
- $foo = $request->GetInputInteger("Foo");
- //read the value of the Bars from the request input
- $foo = $request->GetInputArray("Bar");
- //read the value of the Email variable from the request input, validating that it's an email address
- $$email = $request->GetInputEmailAddress("Email");
- return $this->createResponseFromRequest($request, $app);
DblEj\Communications\Http\Request provides standard methods for accessing information about the request and makes dealing with HTTP inputs reliable and easy.