1

我有同样的问题 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';
    }
}

这是我的 routing.yml

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

路由.yml

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

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

编辑:

FileLoaderImportCircularReferenceException:在“/app/config/routing_dev.yml”中检测到循环引用(“/app/config/routing_dev.yml”>“/app/config/routing.yml”>“.”>“@GabrielAdminPanelBundle/Controller/” >“/app/config/routing_dev.yml”)。

4

1 回答 1

1

您还必须配置服务

# 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
于 2015-01-21T18:32:56.087 回答