Reputation: 68396
I am building a symfony2 application, and I want to split the functionality into two "sites", for example:
[Clarification]
I have already read the documentation pointed out by others below, but Symfony is throwing an exception, with the following error message :
The parameter "domain" must be defined (500 Internal Server Error)
This is what I have done so far:
My routing.yml file looks like this
foobar_homepage:
path: /
host: "foobar.{domain}"
defaults:
_controller: AcmeDemoBundle:Main:foobarHomepage
domain: "%domain%"
requirements:
domain: "%domain%"
homepage:
path: /
defaults: { _controller: AcmeDemoBundle:Main:homepage }
I don't want to hardcode the domain name - so I can use the same codebase and configuration, for multiple sites.
I already have the domain name in the request object. The problem is that its's not clear how to pass that parameter to the route.
So how can I pass the domain name in a DRY fashion, in order to satisfy the route requirement?
Upvotes: 1
Views: 443
Reputation: 13265
If you want fully dynamic host parsing in route without any hardcoded value you should omit default value and requirements for your route. It should look like that:
foobar_homepage:
path: /
host: "foobar.{domain}"
defaults:
_controller: AcmeDemoBundle:Main:foobarHomepage
Upvotes: 1
Reputation: 3697
You can even make dynamic subdomains. This is a nice video tutorial about it: http://knpuniversity.com/screencast/question-answer-day/symfony2-dynamic-subdomains
Upvotes: 0
Reputation: 393
Is your problem the route matching? If yes, take a look at the symfony documentation: http://symfony.com/doc/current/components/routing/hostname_pattern.html
Upvotes: 0