1.启用bundle
new \Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle()
2.配置
cmf_routing: chain: routers_by_id: router.default: 200 cmf_routing.dynamic_router: 100 dynamic: persistence: orm: enabled: true
3.创建orm_routes数据库表
bin/console doctrine:schema:update —force
4.在数据库中添加路由
$route = new Route(); $route->setName('dynamic_route_test'); $route->setStaticPrefix('/test'); $route->setVariablePattern('/{name}'); $route->setDefaults([ '_controller'=> 'AcmeBundle:Index:index' ]);
5.访问/test/dynamic 会匹配到dynamic_route_test路由,并执行IndexController的indexAction。