Skip to content

Commit 55616d8

Browse files
committed
[HttpKernel] Explain how to define default value in MapQueryString
1 parent b8f6679 commit 55616d8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

controller.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,24 @@ HTTP status to return if the validation fails::
451451

452452
The default status code returned if the validation fails is 404.
453453

454+
If the request query string is empty and if you still need to have a valid DTO, you can
455+
define a default value in your controller method::
456+
457+
use App\Model\UserDto;
458+
use Symfony\Component\HttpFoundation\Response;
459+
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
460+
461+
// ...
462+
463+
public function dashboard(
464+
#[MapQueryString] UserDTO $userDto = new UserDTO()
465+
): Response
466+
{
467+
// ...
468+
}
469+
470+
In this case your DTO should have default values.
471+
454472
.. versionadded:: 6.3
455473

456474
The :class:`Symfony\\Component\\HttpKernel\\Attribute\\MapQueryString` attribute

0 commit comments

Comments
 (0)