Reputation: 3530
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" }
Upvotes: 4
Views: 9029
Reputation: 1271
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.
Upvotes: 5
Reputation: 2677
In routing YAML:
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 okay with that. In a Twig template:
{% render "Org\\FancyBundle\\Controller\\Page\\Blog\\CommentsController::listAction" with {} %}
I've never had any problems with escaping that I know of. Symfony 2.0.9, PHP 5.3.9 on Windows/IIS (sigh)
Upvotes: 0
Reputation: 3530
I relsoved exposing my controller as service
post:
pattern: /
defaults: { _controller: "my.controller.service.id:indexAction" }
Upvotes: 2
Reputation: 1150
try this: replace the slash with the backslash
post:
pattern: /
defaults: { _controller: "HavactBlogBundle:Backend\Post:index" }
Upvotes: 16