Symfony2: Route Controllers and Views in Subdirectories

I am developing a package with frontend and backend. I am following instructions on the best way to structure controllers and views for backend and frontend components here and here . But I can't find how to specify the subdirectories in my routing config file. I am trying to do this, but it doesn't work.

  pattern:  /
  defaults: { _controller: "HavactBlogBundle:Backend/Post:Backend/index" }



source to share

4 answers

I am relsoved by exposing my controller as a service

pattern:  /
defaults: { _controller: "" }




try this: replace the forward slash with a backslash

    pattern:  /
    defaults: { _controller: "HavactBlogBundle:Backend\Post:index" }




For those people who don't want to show their controllers as a service (which is an indirect solution to the problem), you specify the route as such.

route_name: path: /path defaults: { _controller: BundleName:Namespace/Controller:action }


is your subdirectory in the bundle directory Controller

, followed by /

to split it.

All others should work the same way.



In YAML routing:

defaults: { _controller: Org\FancyBundle\Controller\Page\Blog\CommentsController::fancyAction }


The difference here is that I don't use quotes around the string, and YAML is fine with that. In Twig template:

{% render "Org\\FancyBundle\\Controller\\Page\\Blog\\CommentsController::listAction" with {} %}


I've never had a problem with the escape that I know of. Symfony 2.0.9, PHP 5.3.9 for Windows / IIS (sigh)



All Articles