8000 [Routing] add support for optional placeholders in the host · Issue #7306 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] add support for optional placeholders in the host #7306

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
Tobion opened this issue Mar 8, 2013 · 23 comments
Closed

[Routing] add support for optional placeholders in the host #7306

Tobion opened this issue Mar 8, 2013 · 23 comments

Comments

@Tobion
Copy link
Contributor
Tobion commented Mar 8, 2013

Optional placeholders are not implemented yet for the host (unlike the path).
So given {subdomain}.domain.com it cannot match domain.com because the dot is statically required.

Ref. #6821

@rcwsr
Copy link
rcwsr commented Mar 20, 2013

This would be perfect for what I need as well. Without it I'm going to have to double the amount of routes I already have.

@cevou
Copy link
cevou commented Apr 8, 2013

+1

@rcwsr
Copy link
rcwsr commented Apr 17, 2013

The problem with using an extra route is that it messes with url generators. Take the following routes:

homepage:
    pattern: /
    host: "{site}.site.com"
    defaults: { _controller: SitePageBundle:Homepage:show, slug: ""}
homepage_default:
    pattern: /
    host: "site.com"
    defaults: { _controller: SitePageBundle:Homepage:show, slug: "", site: "default"}

If I visit sub.site.com then urls are generated correctly i.e. sub.site.com/news. If however I visit site.com any generated urls will point to default.site.com. It could be solved, but I don't really want more if statements in my templates.

I suppose it depends on how your project works, but I'd greatly appreciate optional routes.

@xmarcos
Copy link
xmarcos commented Oct 5, 2013

@Tobion maybe a better implementation would be to also allow multiple options in the host (as an array)? I'll try to make a PR next week.

@Tobion
Copy link
Contributor Author
Tobion commented Oct 5, 2013

@xmarcos what you mean? the params in the host can be any regex, so you can already have multiple matches

@xmarcos
Copy link
xmarcos commented Oct 5, 2013

I mean multiple hosts not multiple patterns in the same host.

In the example above

So given {subdomain}.domain.com it cannot match domain.com because the dot is statically required.

Instead of making {subdomain} optional, a different solution may be to accept and array of patterns in the host:, like:

homepage:
    pattern: /
    host: ["{site}.site.com", "admin.{site}.site.com", "site.com", "site.dev"]

@Tobion
Copy link
Contributor Author
Tobion commented Oct 5, 2013

this doesnt really work because the generator wouldnt know which host to generate. also you could have potentially different params in there which wouldnt work either

@atlantislt
Copy link

+1

2 similar comments
@asJulius
Copy link

+1

@darceee2
Copy link

+1

@mansoff
Copy link
mansoff commented Apr 16, 2014

jap, +1

@st0at
Copy link
st0at commented Apr 22, 2014

+1

8 similar comments
@artaxmax
Copy link

+1

@jpsk
Copy link
jpsk commented May 2, 2014

+1

@belauzas
Copy link
belauzas commented May 2, 2014

+1

@beccha
Copy link
beccha commented Jul 27, 2015

+1

@mowcixo
Copy link
mowcixo commented Aug 10, 2015

+1

@vitalyiegorov
Copy link

+1

@jonathanbull
Copy link

+1

@eversonaraujo
Copy link

+1

@nicolas-grekas
Copy link
Member

Anyone willing to submit an implementation?

@nicolas-grekas
Copy link
Member

Actually there was one which has been closed unreviewed: #10254
Anyone willing to take over/review/try/validate/etc., please do!

@Tobion
Copy link
Contributor Author
Tobion commented Sep 6, 2019

Closing as I haven't had the need for this yet. If someone else needs the feature, feel free to create a PR.

@Tobion Tobion closed this as completed Sep 6, 2019
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

0