twig path() function generating different outcome

11,023

Add a default value in the annotation to the controller:

@Route("/boek/{id}", defaults={"id" = 1}, name="single_sale_submit_page")

Clear the cache with:

app/console cache:clear

After reloading the paths generated by path() will correspond to:

../book/123456789

and not:

../book/?id=123456789
Share:
11,023
ExcellentAverage
Author by

ExcellentAverage

Updated on June 04, 2022

Comments

  • ExcellentAverage
    ExcellentAverage almost 2 years

    I am trying to add dynamic links to my twig template by calling path() with a parameter.

    {{ path('single_sale_submit_page', {'id': book['id']}) }}
    

    I use annotation in my controller:

    @Route("/book/{id}", name="single_sale_submit_page")
    

    This results in the following url: ../book/?id=123456789. I keep getting the error that my controller needs a mandatory parameter, which is of course true cause the generated url has a different syntax(?).

    How can I set up twig in a way that the generated url from path() corresponds to

    ../book/123456789
    

    and not

    ../book/?id=123456789
    

    EDIT: This question has somewhat the same question as I have.