Symfony2 在自定义路由加载器上找不到路由


Symfony2 can't find Route on custom Route Loader

我遇到了symfony2在这里描述的相同问题

当您有捆绑包但不想手动时,这会派上用场 将捆绑包的路由添加到 app/config/routing.yml 。这可能是 当您想要使捆绑包可重用时尤其重要

TLDR;我试图使用symfony2文档的这一部分实现自定义路由加载程序http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html#more-advanced-loaders

但是它似乎不起作用,找不到路线;

这是我到目前为止尝试过的:加载器:

<?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';
    }
}

这是我的路由.yml

located in: src/Gabriel/AdminPanelBundle/Resources/config/routing.yml

The Ruting.yml

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

除非我将路由放回主app/config/routing.yml文件中,否则找不到捆绑包的路由,如何解决这个问题?

编辑:

文件加载程序导入循环引用异常:循环引用 在"/app/config/routing_dev.yml"中检测到 ("/app/config/routing_dev.yml"> "/app/config/routing.yml"> "."> "@GabrielAdminPanelBundle/控制器/"> "/app/config/routing_dev.yml")。

您还必须配置服务

# src/Gabriel/AdminPanelBundle/Resources/config/services.yml
your_bundle.routing_loader:
    class: Gabriel'AdminPanelBundle'Routing'AdvancedLoader
    tags:
        - { name: routing.loader }

和路由文件

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