Skip to content

Commit 02a2e4d

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: [HttpKernel] Explain how to define default value in MapQueryString
2 parents 6ffabcc + e9a379e commit 02a2e4d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

controller.rst

+16
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,22 @@ HTTP status to return if the validation fails::
442442

443443
The default status code returned if the validation fails is 404.
444444

445+
If you need a valid DTO even when the request query string is empty, set a
446+
default value for your controller arguments::
447+
448+
use App\Model\UserDto;
449+
use Symfony\Component\HttpFoundation\Response;
450+
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
451+
452+
// ...
453+
454+
public function dashboard(
455+
#[MapQueryString] UserDTO $userDto = new UserDTO()
456+
): Response
457+
{
458+
// ...
459+
}
460+
445461
.. _controller-mapping-request-payload:
446462

447463
Mapping Request Payload

0 commit comments

Comments
 (0)