Dener K. Dener K. - 1 year ago 69
PHP Question

Why symfony does not recognize the route with placeholders

I have the following route in php

$collection->add('verify', new Route('/verify/{confirmation}', array(
'_controller' => 'AppBundle:Verify:verify',

And I want to generate a url with the confirmation parameter

$url = $this->generateUrl('verify', array('confirmation' => $user-> getConfirmation()));

and show it on a twig template

a href="{{ url('url') }}"

but I'm getting this error

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "url" as such route does not exist.") in Emails/registration.html.twig at line 5.
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception: RouteNotFoundException ยป

what am I doing wrong?

Answer Source

In you twig template change a href="{{ url('url') }}" to:

a href="{{ url('verify', {'confirmation': app.user.confirmation}) }}"

or {'confirmation': confirmation} and make sure to pass confirmation variable to template from controller.