Skip to content
Advertisement

Symfony2 Accessing route variables

I know I can access current route name by $request->get('_route');.

If my route is defined this way:

/*
 * @Route("/get_by_category/{id}", defaults={"id" = 0}, name="get_products_by_category")
 */

How can I retrieve the id variable from within service?

Advertisement

Answer

$request->attributes->get('id') does the trick.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement