Symfony2 在自定义路由加载器上找不到路由
Symfony2 can't find Route on custom Route Loader
我遇到了 symfony2 描述的同样问题 here
This comes in handy when you have a bundle but don't want to manually
add the routes for the bundle to app/config/routing.yml
. This may be
especially important when you want to make the bundle reusable
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
routing.yml
gabriel_admin_panel:
resource: "@GabrielAdminPanelBundle/Controller/"
type: annotation
prefix: /superuser
除非我将路由放回主 app/config/routing.yml 文件中,否则找不到包的路由,如何解决这个问题?
编辑:
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").
您还必须配置服务
# 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
我遇到了 symfony2 描述的同样问题 here
This comes in handy when you have a bundle but don't want to manually add the routes for the bundle to
app/config/routing.yml
. This may be especially important when you want to make the bundle reusable
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
routing.yml
gabriel_admin_panel:
resource: "@GabrielAdminPanelBundle/Controller/"
type: annotation
prefix: /superuser
除非我将路由放回主 app/config/routing.yml 文件中,否则找不到包的路由,如何解决这个问题?
编辑:
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").
您还必须配置服务
# 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