Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] Default locale in routes #9981

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
MAXakaWIZARD opened this issue Jan 9, 2014 · 13 comments
Closed

[Routing] Default locale in routes #9981

MAXakaWIZARD opened this issue Jan 9, 2014 · 13 comments
Labels

Comments

@MAXakaWIZARD
Copy link
Contributor

Consider example from docs

contact:
    path:      /{_locale}/contact
    defaults:  { _controller: AcmeDemoBundle:Contact:index, _locale: en }
    requirements:
        _locale: en|fr|de

As docs say it should apply default locale for path /contact
But it doesn't:

php app/console router:match /contact
None of the routes matches

However, it works for route (optional placeholder is last in path):

wre_index:
    path:  /{_locale}
    defaults: { _controller: AcmeDemoBundle:Index:index, _locale: en }
    requirements:
        _locale: en|fr|de

This was checked on Symfony Standard 2.4.1 and 2.4.0

@jakzal
Copy link
Contributor

jakzal commented Jan 9, 2014

That's because optional parameters can only be defined at the end of the path. See #5424.

@derrabus
Copy link
Member

derrabus commented Jan 9, 2014

Documentation: http://symfony.com/doc/current/book/routing.html#required-and-optional-placeholders

When just reading the docs, I wouldn't think, that optional parameters only work at the end of a URL. So, maybe this is a docs issue?

@MAXakaWIZARD
Copy link
Contributor Author

@cordoval
Copy link
Contributor

cordoval commented Jan 9, 2014

it is indeed incorrect then, let's close this and i have opened symfony/symfony-docs#3450

@derrabus
Copy link
Member

derrabus commented Jan 9, 2014

👍

@alquerci
Copy link
Contributor

alquerci commented Jan 9, 2014

@MAXakaWIZARD Can you explain why the route /contact can match one of these:

  • /en/contact
  • /fr/contact
  • /de/contact.

IMHO it's weird to have optional placeholder on the path. The doc say:

Unfortunately, this violates a fundamental rule of the Web: that a particular URL returns the same resource regardless of the user. To further muddy the problem, which version of the content would be indexed by search engines?

EDIT after #9981 (comment):
Ho, sorry I don't want to say, the route contact but the path /contact. That's two different things.
So the path /contact cannot match with one of these paths:

  • /en/contact
  • /fr/contact
  • /de/contact

@MAXakaWIZARD
Copy link
Contributor Author

@alquerci It should match, another thing is that you should redirect from /en/contact to /contact, but that's different problem

@alquerci
Copy link
Contributor

alquerci commented Jan 9, 2014

@MAXakaWIZARD Ho, sorry I don't want to say, the route contact but the path /contact. That's two different things.

It's ok that the route contact should match these paths, to avoid redirection:

  • /contact EDIT: without this path
  • /en/contact
  • /fr/contact
  • /de/contact

@MAXakaWIZARD
Copy link
Contributor Author

@alquerci I think if en is default locale, then you anyway should redirect from /en/contact to /contact to avoid content duplication

@alquerci
Copy link
Contributor

alquerci commented Jan 9, 2014

@MAXakaWIZARD I said really wrong things, sorry for that.

I just wanted to clarify that the doc does not say that the route contact match the path /contact. For do it you need to create an another route who match the path /contact and added the right redirection as you said. Unfortunately this adds code duplication.

There may be another way to do the same thing, like @jakzal said #9981 (comment).

@xabbuh
Copy link
Member

xabbuh commented Jan 9, 2014

I just wanted to clarify that the doc does not say that the route contact match the path /contact. For do it you need to create an another route who match the path /contact and added the right redirection as you said. Unfortunately this adds code duplication.

This shouldn't be a problem since you can use the RedirectController of the FrameworkBundle in your routing config.

@Tobion
Copy link
Contributor

Tobion commented Jan 16, 2015

Closing as the actual feature is part of #5424. And the documentation has been updated to clarify the current behavior and confusion that it's not possible yet.

@geggert
Copy link

geggert commented Jul 6, 2016

Maybe I solved this in a reasonably simple way:

contact:
    path:      '/{_locale}{_S}contact'
    defaults:  { _controller: 'AppBundle:Example:index' , _locale="de" , _S: "/" }
    requirements:
        _S: "/?"
        _locale: '|de|en|fr'

Curious about the judgement of the critics ...
Best wishes,
Greg


First amendment ...
When you activatie symfony's authentication system and use the login form be sure to use your ROUTES as "*_path"-es (enter the route names there as value, not the virtual path)!

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

No branches or pull requests

8 participants