在 routing_dev.yml 中检测到循环引用

Circular reference detected in routing_dev.yml

我对这个 循环引用 问题很着迷,我找不到我做错了什么。这是/app/config/routing.yml的内容:

pd_one:
    resource: "@PDOneBundle/Controller/"
    type:     annotation
    prefix:   /

template:
    resource: "@TemplateBundle/Controller/"
    type:     annotation
    prefix:   /

fos_user:
    prefix: /admin
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

restful_services:
    resource: "@PDOneBundle/Resources/config/routing.yml"
    type:     rest
    prefix:   /api

nelmio_apidoc:
    resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
    prefix:   /api/doc

admin:
    resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix: /admin

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

这是/app/config/routing_dev.yml的内容:

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /_configurator

_errors:
    resource: "@TwigBundle/Resources/config/routing/errors.xml"
    prefix:   /_error

_main:
    resource: routing.yml

最后是/src/PDI/PDOneBundle/Resources/config/routing.yml的内容:

service_company:
    type: rest
    prefix: /v1
    resource: PDOneBundle\Controller\CompanyRestController
    name_prefix:  api_1_ # naming collision

每当我在 dev 环境中尝试一些 URL 时,我都会收到此错误:

FileLoaderImportCircularReferenceException in classes.php line 7527: Circular reference detected in "/var/www/html/reptooln_admin/app/config/routing_dev.yml" ("/var/www/html/reptooln_admin/app/config/routing_dev.yml" > "/var/www/html/reptooln_admin/app/config/routing.yml" > "/var/www/html/reptooln_admin/src/PDI/PDOneBundle/Resources/config/routing.yml"

"/var/www/html/reptooln_admin/app/config/routing_dev.yml").

这是完整的堆栈跟踪|日志:

in classes.php line 7527
at FileLoader->import('/var/www/html/reptooln_admin/app/config/routing_dev.yml', null, false, '/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml') in YamlFileLoader.php line 155
at YamlFileLoader->parseImport(object(RouteCollection), array('resource' => '/var/www/html/reptooln_admin/app/config/routing_dev.yml'), '/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml', '/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml') in YamlFileLoader.php line 91
at YamlFileLoader->load('/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml', 'yaml') in DelegatingLoader.php line 45
at DelegatingLoader->load('/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml', 'yaml') in DelegatingLoader.php line 58
at DelegatingLoader->load('/var/www/html/reptooln_admin/app/cache/dev/assetic/routing.yml', 'yaml') in classes.php line 11649
at Router->getRouteCollection() in classes.php line 11619
at Router->getGeneratorDumperInstance() in classes.php line 11600
at Router->getGenerator() in classes.php line 11545
at Router->generate('_profiler', array('token' => 'ccd0d6')) in WebDebugToolbarListener.php line 66
at WebDebugToolbarListener->onKernelResponse(object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher))
at call_user_func(array(object(WebDebugToolbarListener), 'onKernelResponse'), object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher)) in WrappedListener.php line 61
at WrappedListener->__invoke(object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher))
at call_user_func(object(WrappedListener), object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher)) in classes.php line 12147
at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(FilterResponseEvent)) in classes.php line 12080
at EventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in classes.php line 12241
at ContainerAwareEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in TraceableEventDispatcher.php line 112
at TraceableEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in bootstrap.php.cache line 3049
at HttpKernel->filterResponse(object(Response), object(Request), '2') in bootstrap.php.cache line 3044
at HttpKernel->handleRaw(object(Request), '2') in bootstrap.php.cache line 2991
at HttpKernel->handle(object(Request), '2', true) in bootstrap.php.cache line 3140
at ContainerAwareHttpKernel->handle(object(Request), '2', true) in ExceptionListener.php line 58
at ExceptionListener->onKernelException(object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
at call_user_func(array(object(ExceptionListener), 'onKernelException'), object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher)) in WrappedListener.php line 61
at WrappedListener->__invoke(object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher))
at call_user_func(object(WrappedListener), object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher)) in classes.php line 12147
at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener)), 'kernel.exception', object(GetResponseForExceptionEvent)) in classes.php line 12080
at EventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in classes.php line 12241
at ContainerAwareEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in TraceableEventDispatcher.php line 112
at TraceableEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in bootstrap.php.cache line 3061
at HttpKernel->handleException(object(FileLoaderLoadException), object(Request), '1') in bootstrap.php.cache line 2997
at HttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 3140
at ContainerAwareHttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 2384
at Kernel->handle(object(Request)) in app_dev.php line 14

问题出在哪里?我做错了什么?我正在尝试设置 NelmioApiDoc 和 FOSRestBundle

编辑 1

我已经解决了上一个问题,但又遇到了一个类似的问题。这是我所做的更改。

/app/config/routing.yml

#PDOne 
# just leave in .yml file
pdone:
    resource: "@PDOneBundle/Resources/config/routing.yml"

# comment this out just for find where is the problem
#template:
#    resource: "@TemplateBundle/Controller/"
#    type:     annotation
#    prefix:   /

#FOSUserBundle
fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    prefix: /

NelmioApiDocBundle:
    resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
    prefix:   /api/doc

#SonataAdmin
admin:
    resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix: /admin

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

/src/PDI/PDOneBundle/Resources/config/routing.yml

#sets this one as annotation
pdone:
    type:     annotation
    prefix:   /
    resource: "@PDOneBundle/Controller/"

#this ones will be for restful API
companies:
    type: rest
    prefix: /api/v1/companies
    resource: PDOneBundle\Controller\Rest\CompanyRestController

错误改为:

FileLoaderImportCircularReferenceException in classes.php line 13960: Circular reference detected in "/var/www/html/reptooln_admin/app/config/routing_dev.yml" ("/var/www/html/reptooln_admin/app/config/routing_dev.yml" > "/var/www/html/reptooln_admin/app/config/routing.yml" > "/var/www/html/reptooln_admin/src/PDI/PDOneBundle/Resources/config/routing.yml"

"PDOneBundle\Controller\Rest\CompanyRestController" > "/var/www/html/reptooln_admin/app/config/routing_dev.yml").

/src/PDI/PDOneBundle/Resources/config/routing.yml 哪里出了问题?不能在同一个 YML 文件中使用 annotationrest 类型?我该如何处理?

循环引用错误其实是错误的,是加载路由时出错(错误触发controller调用,controller要求加载路由,routes loading再次触发错误,...)。

您应该检查 PDOneBundle 和 TemplateBundle 控制器是否存在路由错误,例如缺少 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route 和此类错误。

感谢 Symfony2 上的用户 group I have found a workaround and I will share here. After do a long research I found this SO 主题等等,是的,没有提到 annotations 和混合配置文件或任何导致 循环引用,简而言之,我只是删除了这个:

companies:
    type: rest
    prefix: /api/v1/companies
    resource: PDOneBundle\Controller\Rest\CompanyRestController

来自各个地方,只依赖注释,这对我有用。这不能帮助我找到真正的问题,但至少可以让我的应用程序再次运行。希望这对遇到同样问题的人有所帮助