Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Subdomain Routing - Different Bundles

Tags:

php

symfony

EDIT There is now the possibility of doing this in symfony 2.2

PlatformFooBundle:
    resource: "@PlatformFooBundle/Resources/config/routing.php"
    domain: foo.testdomain.com

PlatformBarBundle:
    resource: "@PlatformBarBundle/Resources/config/routing.php"
    domain: bar.testdomain.com

PlatformBazBundle:
    resource: "@PlatformBazBundle/Resources/config/routing.php"
    domain: baz.testdomain.com

You can use parameters in the domain as well

EDIT OVER

Before marking this as a duplicate, read on

http://www.craftitonline.com/2011/08/symfony2-locale-on-subdomains-not-on-the-url-path/

I've read this article, but it doesnt help me do what im trying to do.

i have 3 different applications that are running on the same domain name, with seperate subdomains. Currently, theya re all running in their own symfony install, and i'd like to get rid of that.

foo.testdomain.com
bar.testdomain.com
baz.testdomain.com

each of these use different bundles

PlatformFooBundle
PlatformBarBundle
PlatformBazBundle

and they each have their own route definitions.

basically, what i want is this

PlatformFooBundle:
    resource: "@PlatformFooBundle/Resources/config/routing.php"
    subdomain: www|devwww

PlatformBarBundle:
    resource: "@PlatformBarBundle/Resources/config/routing.php"
    subdomain: bar|devbar

PlatformBazBundle:
    resource: "@PlatformBazBundle/Resources/config/routing.php"
    subdomain: baz|devbaz

how do i go about doing this?

like image 219
Ascherer Avatar asked May 07 '12 23:05

Ascherer


2 Answers

There is a discussion going on to add this feature.

like image 81
Mun Mun Das Avatar answered Nov 06 '22 22:11

Mun Mun Das


Have a look at ExperiumDomainedRoutingBundle, which is working really well for me. I haven't added a Bundle-wide domain route (only per controller using annotations), but I would expect that work as well.

Example:

/**
 * @Route("/", name="frontend_show", options = {"domain_pattern"="{username}.%base_domain%"})
 * @Route("/u/{username}", name="private_show")
 * @Template("SiteBundle:Frontend:show.html.twig")
 */
like image 28
cvaldemar Avatar answered Nov 06 '22 21:11

cvaldemar