【发布时间】:2020-08-13 17:01:48
【问题描述】:
我正在将遗留项目路由 (Yii1) 迁移到 Symfony 5
现在我的config/routing.yaml 看起来像这样:
- {path: '/login', methods: ['GET'], controller: 'App\Controller\RestController::actionLogin'}
- {path: '/logout', methods: ['GET'], controller: 'App\Controller\RestController::actionLogout'}
# [...]
- {path: '/readme', methods: ['GET'], controller: 'App\Controller\RestController::actionReadme'}
如您所见,有大量重复的 url 到 action 转换。
是否可以根据某些参数动态解析控制器方法。例如
- {path: '/{action<login|logout|...|readme>}', methods: ['GET'], controller: 'App\Controller\RestController::action<action>'}
一种选择是编写注释,但这对我不起作用并抛出Route.php not found
【问题讨论】:
标签: symfony url-routing fosrestbundle symfony5