Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: Routing controllers and views in subdirectories

I'm developing a bundle with frontend and backend. I follow instructions about the best way to structure controllers and views for backend and frontend parts here and here. But I can't find how to specify subdirectories in my routing configuration file. I try to put this, but it does not work.

post:
  pattern:  /
  defaults: { _controller: "HavactBlogBundle:Backend/Post:Backend/index" }
like image 444
smoreno Avatar asked Nov 29 '22 09:11

smoreno


2 Answers

try this: replace the slash with the backslash

post:
    pattern:  /
    defaults: { _controller: "HavactBlogBundle:Backend\Post:index" }
like image 181
Lhassan Baazzi Avatar answered Nov 30 '22 21:11

Lhassan Baazzi


For those people not wanting to expose 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's Controller directory followed by / to separate it.

All else should work just the same.

like image 24
John Pancoast Avatar answered Nov 30 '22 22:11

John Pancoast