在另一个问题中,我问如何在SF2中动态生成路由(因为我想在路由上强制前缀),它工作正常:
如何在容器编译之前将自定义路由添加到 Symfony 2?
问题是这些路由没有缓存,这可能对性能不太好。我想知道我是否在这里做错了什么,如果没有,也许有办法要求 SF2 缓存我的路由?
我在这里遵循了本教程,它似乎对我有用:
http://forum.symfony-project.org/viewtopic.php?t=38793&p=127825
引用:
装载 机:
namespace MyNameMyBundle;
use SymfonyComponentConfigLoaderLoader;
use SymfonyComponentRoutingRouteCollection;
use SymfonyComponentRoutingRoute;
class MyRouteLoader extends Loader
{
public function supports($resource, $type=null)
{
return 'my_new_resource_type' === $type;
}
public function load($resource, $type=null)
{
$collection = new RouteCollection();
$collection->addRoute(new Route(...));
return $collection;
}
}
服务业:
services:
my_route_loader:
class: MyNameMyBundleMyRouteLoader
tags:
- {name: routing.loader}