-
-
Notifications
You must be signed in to change notification settings - Fork 6
User input
The Input repository is separately maintained at https://github.com/PhpGt/Input
By default, PHP exposes all user input in the superglobal variables $_GET
, $_POST
and $_FILES
, which are readable and writable by any code, including third party libraries.
All superglobals are protected within WebEngine, and instead user input is encapsulated within the Input object, which is available as the input
property of your application's Logic classes.
The get
function of the Input
class will return the data matching the provided key, or null if the user input doesn't exist.
public function getUserInput() {
// Read the "telephone" parameter from the query string or post body:
$telephone = $this->input->get("telephone");
// Read the "name" parameter, supplying a default if input is empty:
$name = $this->input->get("name") ?? "Anon";
}
It doesn't matter what HTTP verb (GET, POST, PUT, DELETE, etc.) is used for the request as input is accessed in the same way for all verbs.
You can however specify only to load the input value from the querystring, body or files section of the request parameters. This can be done by passing in one of the following constants as the second parameter to the get
function: Input::DATA_QUERYSTRING
, Input::DATA_BODY
, Input::DATA_FILES
. The default is Input::DATA_COMBINED
.
// getFile
// getDateTime
// has
// hasValue
// hasQueryStringParameter
// hasBodyParameter
// hasFile
The code in your application's Logic classes has full access to the user input, but you don't want to pass all user input around to all other areas of code. Instead, it is possible to call functions with only the user input they are required to know about. For example, in an e-commerce application, only the payment processor needs to be handed the user's credit card details, and not any other areas of code.
// with
returns a Trigger
// when
only calls callback when provided input is present
// Shorthand for when - easily hook up button presses to callbacks
// Square brackets - MultipleInputDatum
// getMultipleFile
// getMultipleDateTime
// getFile, getMultipleFile
// move
// getFileInfo, getRealPath, getOriginalName, getOriginalExtension, getSize, getMimeType
// FailedFileUpload
- Request-response lifecycle
- Running your application
- Project layout
- Application architecture
- Web servers
- URIs
- Page view
- Dynamic URIs and pages
- Headers and footers
- Page logic
- Protected globals
- User input
- Cookies
- Sessions
- DOM manipulation
- Custom HTML components
- DOM templates
- Binding data to the DOM
- Database
- Client side assets
- API Webservices
- Security
- Configuration
- Build system
- Coding styleguide