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

时间:2015-05-04 21:16:00

标签: php symfony fosrestbundle symfony-routing nelmioapidocbundle

我对这个循环参考问题感到疯狂,但我无法找到我做错的事情。这是/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 env尝试了一些网址时出现此错误:

  

classes.php第7527行中的FileLoaderImportCircularReferenceException:   检测到的循环引用   " /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

错误更改为:

  

classes.php第13960行中的FileLoaderImportCircularReferenceException:   检测到的循环引用   " /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 \控制器\休息\ CompanyRestController" > " /var/www/html/reptooln_admin/app/config/routing_dev.yml")

  

/src/PDI/PDOneBundle/Resources/config/routing.yml的问题在哪里?在同一个YML文件中无法生成annotationrest种类型?我该如何处理?

2 个答案:

答案 0 :(得分:2)

循环引用错误实际上是错误的,由加载路径时的错误引起(错误触发控制器调用,控制器需要加载路由,路由加载触发错误,......)。

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

答案 1 :(得分:0)

感谢Symfony2 group上的用户,我找到了一个解决方法,我将在这里分享。经过长时间的研究后,我发现this SO主题等等,是的,围绕注释没有提及并混合配置文件或导致循环引用的任何内容,简而言之,我只是删除了这个:

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

来自每个地方,只是依赖于注释,这对我有用。这无助于我找到真正的问题,但至少让我的应用再次运作。希望这能帮助任何有同样问题的人