我遇到了同样的问题,symfony2正在描述here
当你有一个捆绑但不想手动时,这会派上用场 将捆绑的路由添加到
app/config/routing.yml
。这可能是 当你想让包重复使用时尤其重要
TLDR;我试图使用symfony2文档的这一部分实现自定义Route Loader 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
routing.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”&gt;“/ app / config / rrouting.yml”&gt;“。”&gt; “@ GabrielAdminPanelBundle / Controller /”&gt; “/app/config/routing_dev.yml”)。
答案 0 :(得分: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