-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Creating a route with an empty (optional) parameter doesn't work anymore #7316
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
Comments
Thanks, that seems to do the trick! Cannot find this option in the Op 09-03-13 21:30, Abdellatif AitBoudad schreef:
|
I think it's a bug, it must replace defaults values only if it's different than
what do you think @Tobion I can fix this if needed. :) |
strict_requirements
|
Sorry, just deleted my last two postings. Never mind.. |
@xantos05 Temporary solution ;)
|
I will fix it. A null value for an optional parameter should indeed be ignore 8000 d. This is also in line with what I proposed in #5410. |
@Tobion ok, thank :) |
made a PR |
This PR was merged into the 2.2 branch. Commits ------- d7a7434 [Routing] fix url generation for optional parameter having a null value Discussion ---------- [Routing] fix url generation for optional parameter having a null value | Q | A | ------------- | --- | Bug fix? | [yes] | New feature? | [no] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [yes|] | Fixed tickets | [#7316] | License | MIT
when i do not define a default value for the url parameter it does not work. if i do, it works. this is a change from version 2.1 to version 2.2. |
no there is no change |
This still seems to be broken. After migrating my bundles from Symfony 2.1 to 2.2, it seems the router has no problem matching the url, its rather when you generate the url via the router. In my case: ccdn_forum_user_category_index:
path: /{forumName}
defaults: { _controller: CCDNForumForumBundle:UserCategory:index, _locale: en, forumName: default } Will match the route to load the page, but at any point you try to generate this route without for example 'forumName' having a valid value, like: $this->router->generate('ccdn_forum_user_category_index', array('forumName' => ''); Then it just throws this:
In my case, the array value for 'forumName' is set from a variable, that may or may not have null value. When null, that is when the exception is thrown. I would say this is a bug and is still present, as i am on 2.2.11 and im stumped right now, this worked fine in 2.1. |
|
I just found this issue. Was working for me as well in 2.1. I just upgrade to 2.6 and my registration page now fails to load. The issue for me is I have an AJAX lookup on a username field.. but initially that username is empty.
I tried removing the parameter field alltogether.. but then it throws an error saying the field is required. Empty value should be a valid value for username. Why should the above code fail ? |
nvm. I needed to add a null default to the route..
|
Since updating to Symfony 2.2.0 i can't create a route with an empty parameter. This parameter is indicated as optional and worked fine in previous versions of Symfony. Of course i can build in a check but i wonder if this is normal behaviour.
My Route looks like this:
show_products:
path: /showProduct/{size}/{nr}
defaults: { _controller: TestShopBundle:Product:showProduct, nr: 0 }
In Twig:
{{ path('show_product', { 'size': 1, 'nr': entity.nr }) }}
entity.nr sometimes has a null value!
The following error appears:
An exception has been thrown during the rendering of a template ("Parameter "nr" for route "show_product" must match "[^/]++" ("" given) to generate a corresponding URL.") in TestShopBundle:Frontend:index.html.twig at line 270
Probably not a very serious bug but it's not described in the upgrade document -> https://github.com/symfony/symfony/blob/2.2/UPGRADE-2.2.md
The text was updated successfully, but these errors were encountered: