douzheyo2617 2015-04-17 12:36
浏览 29
已采纳

将子域路由添加到Symfony时,FileLoaderImportCircularReferenceException

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条回答 默认 最新

  • doufendi9063 2015-04-17 13:34
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算