没有自定义控制器代码的 Symfony 2 路由

Symfony 2 route with no custom controller code

我在我的 SF2 应用程序中使用注释定义了我的路线,但是有一些页面虽然它们有不同的路线和 Twig 模板,但它们不需要任何控制器代码,这会导致空方法,例如:

/**
 * @Route(
 *      "/courselimit",
 *      name = "course_limit"
 * )
 * @Template("CRMPiccoBundle:Course:Limit.html.twig")
 *
 * @param Request $request
 *
 * @throws \Exception
 */
public function courseLimitAction(Request $request)
{
}

对我来说,这似乎毫无意义且混乱。有没有办法在 SF2 中避免这种情况,而无需将我的所有路由转换为在 YAML 文件中进行管理?

您可以像这样编辑 app/config/routing.yml

# app/config/routing.yml
course_limit:
    path:      /courselimit
    defaults:
        _controller: FrameworkBundle:Template:template
        template: path/Limit.html.twig

示例显示在没有自定义控制器的渲染模板中: http://symfony.com/doc/2.7/templating/render_without_controller.html