-3

I want to replace spaces (%20) by "-" in Symfony 4.4 routes and delete first capital letter of my {slug}.

E.g:

RecipeController.php

 /**
 * @Route("/receta/{title}", name="recipe_show", methods={"GET"})
 */
public function show(Recipe $recipe): Response
{
    return $this->render('recipe/show/show.html.twig', [
        'recipe' => $recipe,
    ]);
}

Now my route shows it.

https://localhost:8000/receta/Pollo%20agridulce%20chino

But I would like to show

https://localhost:8000/receta/pollo-agridulce-chino

In my BD I save "Pollo agridulce chino"

How can I do it?

Cristina
  • 1
  • 1
  • 5

1 Answers1

-1

usually this works best with a "slug" field in your database, you can have it like "/receta/{slug}" and your database "slug" field "pollo-agridulce-chino". You can either add the "slug" manually or use someting like

strtolower(str_replace(' ', '-','Pollo agridulce chino'))

when you save the title in your DB