0

Using Symfony 4.4, I'm trying to generate a route with a query string using the following code:

$this->get('router')->generate('index', ['status' => ['a', 'b']]);

That generates .../?status[0]=a&status[1]=b. I would have expected it to rather be .../?status[]=a&status[]=b.

This is not a huge problem because the URL generated works fine but is rather inconsistent with forms as if a GET form has a multi-valued status field, submitting it would go to the latter URL.

Symfony 5.3 seems to behave similarly.

Is there a way to tell the router not to use indices in multi-valued query string parameters?

1 Answer 1

1

Symfony UrlGenerator uses http_build_query to build query. So is not possible to change easily the behavior.

It may be possible to override/extend actual generator but I don't think is a good idea.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.