0

I'm having quite a few bundles whose routing rules I don't want to include by hand in my main routing.yml, so I'm looking for a way to define a route that is then forwarded to a controller depending on the parameters in the url.

Something like this in my routing.yml:

foo_main:
    path:   /foo/{bundle}/{action}
    defaults: { _controller: "Foo{bundle}Bundle:Api:{action}" }

It should behave like this:

/foo/acme/index -> FooAcmeBundle:Api:indexAction
/foo/bar/show -> FooBarBundle:Api:showAction
...

I already saw there is a custom route provider that could automatically register new routes, if the above is not possible. But I guess I have to add a custom route provider to each bundle, which seems like a unnecessary overhead if each bundle registers its route the same way.

PS: I'm using Symfony 2.3.1 right now.

acme
  • 14,654
  • 7
  • 75
  • 109
  • 1
    Ok, it seems it's not possible and has been asked before: [Convention-based routing in Symfony2](http://stackoverflow.com/questions/16677330/convention-based-routing-in-symfony2) – acme Jun 18 '13 at 13:55
  • actually it is possible , please see my answer - comment if anything unclear :) – Nicolai Fröhlich Jun 26 '13 at 19:49
  • Thanks, actually there is really is something unclear ;-) – acme Jul 01 '13 at 14:10

1 Answers1

0

You can use FOSRestBundle's automatic route generation.

It does not include the bundle-name in the route but you could abuse the @RouteResource annotation to match your bundle name.

An example can be found in the docs under Implicit resource name definition (2nd codeblock).

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • nfir, thanks for your comment. I'm not quite sure if I fully understood it. Could you please give an example that suites my question? – acme Jul 01 '13 at 14:09