Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 twig path with parameter url creation

Tags:

symfony

i got the following:

<a href="{{ path('_be_activatecategory', {'id': category.id, 'active': 1}) }}">Aktivieren</a> 

creates

/backend/categories/activate/8/1

and then i got

<a href="{{ path('_category', {'id': category.id}) }}"> 

which creates

/category?id=1

see the difference? what i want is in the second case exactly like in the first:

/category/1

how can i manage this? why didnt the path() helper creates the correct url with parameters for me?

EDIT:

my routing looks like this:

/**  * @Route("/category/{id}", name="_category")  * @Template()  */ public function categoryAction($id) { 
like image 989
Fabian Avatar asked Mar 28 '13 18:03

Fabian


2 Answers

Make sure your routing.yml file has 'id' specified in it. In other words, it should look like:

_category:     path: /category/{id} 
like image 194
Squazic Avatar answered Sep 17 '22 14:09

Squazic


Set the default value for the active argument in the route.

like image 43
Elnur Abdurrakhimov Avatar answered Sep 17 '22 14:09

Elnur Abdurrakhimov