Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] [MapQueryString] Add docs for new key option #20475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,27 @@ HTTP status to return if the validation fails::

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

If you want to map your object to a nested array in your query with a specific key,
you can use the ``key`` option in your :class:`Symfony\\Component\\HttpKernel\\Attribute\\MapQueryString`
attribute::

use App\Model\SearchDto;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;

// ...

public function dashboard(
#[MapQueryString(key: 'search')] SearchDto $searchDto
): Response
{
// ...
}

.. versionadded:: 7.3

The ``key`` option of ``#[MapQueryString]`` was introduced in Symfony 7.3.

If you need a valid DTO even when the request query string is empty, set a
default value for your controller arguments::

Expand Down
Loading