8000 Parameter "_locale" for route ERROR · Issue #5396 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Parameter "_locale" for route ERROR #5396

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
mrcmorales opened this issue Aug 30, 2012 · 6 comments
Closed

Parameter "_locale" for route ERROR #5396

mrcmorales opened this issue Aug 30, 2012 · 6 comments

Comments

@mrcmorales
Copy link
Contributor

Hello,

This afternoonI have done a composer update.

After update my app not works, I obtained this error:

An exception has been thrown during the rendering of a template ("Parameter "_locale" for route "portada" must match "[^/]+" ("" given).") in "BlogBundle:Default:portada.html.twig".

I fixed the version "symfony/symfony": "v2.1.0-RC2", in composer.json and now works again.

This is the commit that generate the error: - Updating symfony/symfony (dev-master)
Checking out 2cf50b7

I write this issue to inform the error.

Thanks

Regards

@stof
Copy link
Member
stof commented Aug 30, 2012

Well, the error appears when generating the route portada, in a template provided by BlogBundle. None of them comes from Symfony itself, so we cannot help without more information about them

@mrcmorales
Copy link
Contributor Author

Yes but if i fix Symfony v2.1.0-RC2 works correct.

This is the route:

portada:
  pattern: /{_locale}/
  defaults: { _controller: BlogBundle:Default:portada, _locale: null}
  requirements:
        _locale: ca|es|en|fr|de

What information Can I give you?

Thanks

Regards

@Tobion
Copy link
Contributor
Tobion commented Aug 31, 2012

The commit that "causes" the new behavior is: 0706d18
But the problem lies in your code and the commit just hightlights it, when it previously just ignored it and let your link be wrong. So this is a good thing.

There 2 things that are probably wrong:

  1. The default _locale: null for your route doesn't make sense. Because this default can never reach your controller, i.e. be returned by the matching process. This is because in your route _locale is always required to match this route (because of the trailing slash). So you can simply remove this default or change it to something that passes the requirements, e.g. en.
  2. The real problem is that you either didn't pass the _locale parameter at all to the generator (e.g. twigs path function) which should in general raise an exception that the required parameter is missing, but was hidden by your strange default. Or the other reason may be that you passed an empty _locale parameter directly yourself, which is wrong for the reason as explained by the exception you get.

I guess your route pattern was at some time /{_locale} (without trailing slash). Then your config makes sense and should work without changes. But with the trailing slash you need to make the above changes.

@Tobion
Copy link
Contributor
Tobion commented Aug 31, 2012

I have an idea how to help people to not declare param defaults that can never be returned by the matching process (which would also make this error obvious when compiling the route already).
See PR #5400.

@Tobion
Copy link
Contributor
Tobion commented Sep 4, 2012

Please close this issue.

@mrcmorales
Copy link
Contributor Author

Thanks for help, the problem was in my routing.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0