8000 Route with default value for query string param causes param to get eaten · Issue #10940 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Route with default value for query string param causes param to get eaten #10940

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

Closed
nickshanks opened this issue May 19, 2014 · 2 comments
Closed

Comments

@nickshanks
Copy link

Given a route like this:

book:
    path: /book
    defaults:
        page: 1

I would expect generate('book', {'page': $page}) to generate these routes:

  1. /book when $page == 1
  2. /book?page=2 when $page == 2

What actually happens is that when a parameter has a default value, but is not present in the route path, it just gets eaten by Symfony. Both of the above values for $page result in the path /page being generated.

@Tobion
Copy link
Contributor
Tobion commented May 19, 2014

This was "fixed" but got reverted because of BC break. See #7458 and #5410

@nickshanks
Copy link
Author

I had seen #5410 but not #7458 which is probably the more important PR from my point of view. Did the "fix the documentation" issue get addressed? I saw nothing that addressed this known bug (i.e. inconsistent behaviour that can't be fixed for legacy reasons).

The other option is to introduce a new function (say, make()) that does preserve query string arguments even when they have a default value. There are a few more possibilities too.

fabpot added a commit that referenced this issue Apr 15, 2016
…lt (Tobion)

This PR was merged into the 2.3 branch.

Discussion
----------

[Routing] add query param if value is different from default

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | most likely not
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #10940, #18111, #18035
| License       | MIT
| Doc PR        | -

Commits
-------

1ef2edf [Routing] add query param if value is different from default
@fabpot fabpot closed this as completed Apr 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0