1

I have my routes defined using annotations in my SF2 application, however there are a handful of pages which although they have a distinct route and Twig template they require no controller code whatsoever which leads to empty methods such as this:

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

This, to me, seems pointless and messy. Is there a way to avoid this in SF2 without converting all my routes to be managed in YAML files?

crmpicco
  • 16,605
  • 26
  • 134
  • 210

1 Answers1

2

You would edit app/config/routing.yml like so:

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

Examples are shown in the Render Template without a custom Controller: http://symfony.com/doc/2.7/templating/render_without_controller.html

Alvin Bunk
  • 7,621
  • 3
  • 29
  • 45
  • Thanks, I couldn't find anything like that in the documentation earlier. Now i'm in two minds what the best approach or best practice is in this case. Should I define a route in `routing.yml` when all other application-level routes are defined in annotations or should I leave the empty method in the codebase? I'm verging on moving the route to `routing.yml` since there is a Symfony document dedicated to it, so I assume that it must be a common concern. – crmpicco Feb 14 '17 at 05:13
  • 1
    I mis-read your question at first, but it seems using the `routing.yaml` file with no controller is the way to go in your case. – Alvin Bunk Feb 14 '17 at 05:27