简体   繁体   中英

How to fix “Circular reference” error on YAML file?

FileLoaderImportCircularReferenceException: Circular reference detected in "/app/config/routing_dev.yml" ("/app/config/routing_dev.yml" >
"/app/config/routing.yml" > "." > "@GabrielAdminPanelBundle/Controller/" > "/app/config/routing_dev.yml").

I'm trying to achieve this: http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html#more-advanced-loaders

so I created this file

AdvancedLoader.php

<?php
//namespace Acme\DemoBundle\Routing;
namespace Gabriel\AdminPanelBundle\Routing;

use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\RouteCollection;

class AdvancedLoader extends Loader
{
    public function load($resource, $type = null)
    {
        $collection = new RouteCollection();

        $resource = '@GabrielAdminPanelBundle/Resources/config/routing.yml';
        $type = 'yaml';

        $importedRoutes = $this->import($resource, $type);

        $collection->addCollection($importedRoutes);

        return $collection;
    }

    public function supports($resource, $type = null)
    {
        return $type === 'advanced_extra';
    }
}

/src/Gabriel/AdminPanelBundle/Resources/config/services.yml

services:
    gabriel.routing_loader:
        class: Gabriel\AdminPanelBundle\Routing\AdvancedLoader
        tags:
            - { name: routing.loader }

/app/config/routing.yml

gabriel_messaging:
    resource: "@GabrielMessagingBundle/Controller/"
    type:     annotation
    prefix:   /

fos_js_routing:
    resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

# app/config/routing.yml
Gabriel_Extra:
    resource: .
    type: advanced_extra

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

_main:
    resource: routing.yml

/src/Gabriel/AdminPanelBundle/Resources/config/routing.yml

gabriel_admin_panel:
    resource: "@GabrielAdminPanelBundle/Controller/"
    type:     advanced_extra
    prefix:   /superuser

Take a close look at @GabrielAdminPanelBundle/Resources/config/routing.yml :

gabriel_admin_panel:
    resource: "@GabrielAdminPanelBundle/Controller/"
    type:     advanced_extra
    prefix:   /superuser

The type specifies which loader should be used, in this case you said advanced_extra , which is your loader. Your loader includes this file again and the file will execute the loader again, this will continue forever (in other words: a circular reference).


Please also note that you already included the routes in app/config/routing.yml :

gabriel_messaging:
    resource: "@GabrielMessagingBundle/Controller/"
    type:     annotation
    prefix:   /

This time, you use the correct type: annotation . You should remove this entry and edit the @GabrielAdminPanelBundle/Resources/config/routing.yml file to use correct types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM