1
votes

I am trying to route a subdomain to a specific bundle in Symfony2. Here's what I've got:

I added local domains to my hosts:

127.0.0.1    todolist.lc
127.0.0.1    manager.todolist.lc

I created a virtual host that forwards all subdomains to my Symfony installation:

<VirtualHost 127.0.0.1>
 ServerName todolist.lc
 ServerAlias *.todolist.lc
 DirectoryIndex app_dev.php
 DocumentRoot "C:\xampp\htdocs\todolist\web"
</VirtualHost>

I created a new Bundle to handle the subdomain manager.todolist.lc:

ManagerBundle

Now I am trying to set up the route to manager.todolist.lc:

frontend:
    resource: "@FrontendBundle/Controller/"
    type:     annotation
    prefix:   /

backend:
    resource: "@BackendBundle/Controller/"
    type:     annotation
    prefix:   /api

manager:
    host:     manager.todolist.lc
    resource: "@ManagerBundle/Controller/"
    type:     annotation
    prefix:   /

Now after I added the manager route I get a FileLoaderImportCircularReferenceException on every route there is.

I also tried to use a prefix, but this also gives the Exception:

manager:
    resource: "@ManagerBundle/Controller/"
    type:     annotation
    prefix:   /manager

I can't figure out what I am missing. What am I doing wrong? If you need any more info, just ask for it in the comments and I'll provide it.

1

1 Answers

0
votes

Ok. Here's what I was missing:

1. I forgot to load the bundle into the AppKernel

Obviously, this is very important:

new FrontendBundle\FrontendBundle(),
new BackendBundle\BackendBundle(),
new ManagerBundle\ManagerBundle(),

2. The subdomain needs to be declared before the main domain

After I loaded the bundle into the AppKernel the application would still route to the FrontController. I solved this by changing the order of my routes:

manager:
    host:     manager.todolist.lc
    resource: "@ManagerBundle/Controller/"
    type:     annotation
    prefix:   /

frontend:
    resource: "@FrontendBundle/Controller/"
    type:     annotation
    prefix:   /

backend:
    resource: "@BackendBundle/Controller/"
    type:     annotation
    prefix:   /api

After changing the order of the routes both manager.todolist.lc and todolist.lc worked.