Angelo Giuffredi
Angelo Giuffredi

Reputation: 943

Symfony2 - Multiple slug in one route

In Symfony is it possible to access a controller through a route that potentially can contain indefinite number of slug, taking advantage from internal routing system?

e.g.

my_route:
    pattern: /{slug_parent}/{slug_child}/{slug_nephew}/{slug_...}/...

as

www.mydomain.com/math/arithmetic/fractions

but also

www.mydomain.com/tech/android

Upvotes: 2

Views: 2128

Answers (1)

Ladislav M
Ladislav M

Reputation: 2187

It can be done, but instead of creating routes in config YML I would recommend to use @Route annotations. Add annotations in the controller class, like this:

 /**
     * @Route("/{slug_parent}/{slug_child}")
     * @Route("/{slug_parent}/{slug_child}/{slug_nephew}/")
     * @Route("/{slug_parent}/{slug_child}/{slug_nephew}/{slug_...}/")
     */
    public function yourControllerAction()
    {
...
}

http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html

Upvotes: 2

Related Questions