I want to access a specific product from a homepage :
<a href="{{ path('property.show', {id: property.id, slug: property.slug}) }}">{{ property.title }}</a>
I specified the route in the controller
/**
* @Route("/property/{slug}-{id}", name="property.show", requirements={"slug": "[a-z0-9\-]*"})
* @param Property $property
* @return Response
*/
public function show(Property $property, string $slug): Response
{
if ($property->getSlug() !== $slug)
{
return $this->redirectToRoute('property.show', [
'id' => $property->getId(),
'slug' => $property->getSlug()
], 301);
}
$property = $this->repository->find($id);
return $this->render('property/show.html.twig', [
'property' => $property,
'current_menu' => 'properties'
]);
but when I click on the link, I get an error "No route found for "GET /my-first-property/property/-1" (from "http://localhost:8000/")"
The URL I'm trying to generate should be /property/my-first-property-1, I don't understand why it doesn't work.