在Symfony中使用{slug}生成Url

I have the following route for a controller:

/**
 * @Route("/fail/{uid}", name="bookFail", defaults={"uid"=0})
 */

From another controller, I redirect like this:

return $this->redirect($this->generateUrl('bookFail', array('id' => $jobExists->getId())), 301);

Which leads to this:

/hvz/web/app_dev.php/fail?id=XXX

but should be this:

/hvz/web/app_dev.php/fail/XXX

My current solution is this:

$this->redirect(str_replace('?id=','/',$this->generateUrl('bookFail', array('id' => $jobExists->getId()))), 301);

which works but feels wrong on so many levels, what would be the "right" solution for that?

You should be good to go with this :

return $this->redirect($this->generateUrl('bookFail', array('uid' => $jobExists->getId())), 301);

The problem was just in the parameter url you need to have the same name of the parameter in the route definition and in the array params that you passe in the generateUrl function