Search code examples
phpsymfonyroutesurl-encoding

Symfony % causing no route found


I have a controller with a generateQrCodeAction in it:

/**
 * @Route("/qrCode/generate/{eakte}")
 * @param $eakte
 * @return Response
 */
public function generateQrCodeAction($eakte) {
    $qrService = $this->get("app.qrcode");
    $qrService->generate_qr_code($eakte);
    return new Response("done");
}

the eakte parameter is a url encoded one, from a string containing "/" in it. url encoding "/" results in "%2F" in the eakte parameter. However when I test the route /qrCode/generate/800%2F08SL300001 as an example, I get a route not found error. it seems that % is not allowed in routes! is there a workaround for this?


Solution

  • This would allow you to have a "/" in your url parameter

    /**
     * @Route("/qrCode/generate/{eakte}", requirements={"eakte"=".+"})
     */
    

    Source: https://symfony.com/doc/current/routing/slash_in_parameter.html