getParam.php
Table of Contents
Functions
- getParam() : mixed
- Retrieves a parameter from the HTTP request, supporting query string, body, or both.
Functions
getParam()
Retrieves a parameter from the HTTP request, supporting query string, body, or both.
getParam(ServerRequestInterface|null $request, string $name[, array<string|int, mixed> $default = [] ][, string $strategy = HttpParamStrategy::BOTH ][, bool $throwable = false ]) : mixed
This helper searches for the requested parameter $name in the request according to the
specified $strategy:
HttpParamStrategy::QUERY→ only query string parameters.HttpParamStrategy::BODY→ only parsed body parameters.HttpParamStrategy::BOTH→ query string first, then body.
Nested keys are supported via dot notation (e.g., 'user.profile.email').
Body parameters are normalized to an associative array using toAssociativeArray().
If the parameter is not found:
- Returns the corresponding value in
$default[$name]if present. - Returns
nullif no default is provided. - Throws
DI\NotFoundExceptionif$throwableis true.
Parameters
- $request : ServerRequestInterface|null
-
The PSR-7 server request instance.
- $name : string
-
The parameter name or dot-notated path.
- $default : array<string|int, mixed> = []
-
Optional default values as an associative array.
- $strategy : string = HttpParamStrategy::BOTH
-
One of
HttpParamStrategy::QUERY|BODY|BOTH. Default: BOTH. - $throwable : bool = false
-
Whether to throw a
NotFoundExceptionif parameter is missing. Default: false.
Tags
Return values
mixed —The parameter value if found, otherwise the default value or null.