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.

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

      

+3


source to share


4 answers


I am relsoved by exposing my controller as a service



post:
pattern:  /
defaults: { _controller: "my.controller.service.id:indexAction" }

      

+2


source


try this: replace the forward slash with a backslash



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

      

+16


source


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 }

Namespace

is your subdirectory in the bundle directory Controller

, followed by /

to split it.

All others should work the same way.

+5


source


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)

0


source







All Articles