How to use MapQueryString with DTO containing Boolean with 'true' or 'false' value as querystring #52572
Replies: 2 comments
{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
The behavior you're experiencing is expected. PHP interprets query string parameters as strings When you use To handle this, you can implement custom logic in your DTO to manually convert the string class MyDTO
{
// ...
public function setIsFeatured(string|bool $value): void
{
$this->isFeatured = is_string($value) ? 'false' !== $value && '0' !== $value : $value;
}
} If you need a more generic or global solution for the entire application, consider a custom |
Beta Was this translation helpful? Give feedback.
{{title}}
{{editor}}'s edit
{{editor}}'s edit
-
|
Beta Was this translation helpful? Give feedback.
{{title}}
-
Hi,
Considering this class
If I use MapQueryString for the URL /mypage?isFeatured=0 or /mypage?isFeatured=1, the DTO is correctly hydrated. But not when the query string is
isFeatured=true
orisFeatured=false
Is it expected? Is it a bug? What can I do to use
true
orfalse
and the DTO hydrated.Your sincerly
Beta Was this translation helpful? Give feedback.
All reactions