[symfony] symfony2 twig path with parameter url creation

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)
{

This question is related to symfony

The answer is


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


/**
 * @Route("/category/{id}", name="_category")
 * @Route("/category/{id}/{active}", name="_be_activatecategory")
 * @Template()
 */
public function categoryAction($id, $active = null)
{ .. }

May works.


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

_category:
    path: /category/{id}

In Twig:

{% for l in locations %}

<tr>
    <td>
        <input type="checkbox" class="filled-in" id="filled-in-box-{{ l.idLocation }}" />
        <label for="filled-in-box-{{ l.idLocation }}"></label>
    </td>
    <td>{{ l.loc }}</td>
    <td>{{ l.mun }}</td>
    <td>{{ l.pro }}</td>
    <td>{{ l.cou }}</td>
    {#<td>
        {% if l.active == 1  %}
            <span class="fa fa-check"></span>
        {% else %}
            <span class="fa fa-close"></span>
        {% endif %}
    </td>#}
    <td><a href="{{ url('admin_edit_location',{'id': l.idLocation}) }}" class="db-list-edit"><span class="fa fa-pencil-square-o"></span></a>
    </td>
</tr>{% endfor %}

The route admin_edit_location:

admin_edit_location:
  path: /edit_location/{id}
  defaults: { _controller: "AppBundle:Admin:editLocation" }
  methods: GET

And the controller

public function editLocationAction($id){
    // use $id 

    $em = $this->getDoctrine()->getManager();
    $location = $em->getRepository('BackendBundle:locations')->findOneBy(array(
    'id'    => $id
    ));
}