In my project I have members who each have different galleries. I'm looking to make a method that allows me to have all the showrooms associated with my member. I have a OneToMany relationship between member and showroom. I don't understand the error that is returned, it's like my member entity did not want there to be the id of a member in the route of a showroom method. I put dumps in my code which gives me the information I want so I don't see where it's blocking. Can you help me please? I'm on Symfony4
ShowroomController
#[Route('/membre/{id}/showroom', name: 'app_showroom_index', methods: ['GET'])] public function index(int $id, MembreRepository $membreRepository): Response { // Récupérer le membre via son ID $membre = $membreRepository->find($id); if (!$membre) { throw $this->createNotFoundException('Membre introuvable.'); } // Afficher l'ID du membre avec dump() dump($membre->getId()); // ou dump($id) pour afficher directement l'ID reçu dans l'argument // Récupérer les showrooms associés au membre via la relation $showrooms = $membre->getShowrooms(); dump($showrooms->first()); return $this->render('showroom/index.html.twig', ['showrooms' => $showrooms, ]); }
MembreController :
class MembreController extends AbstractController{ #[Route('/membre', name: 'app_membre_index', methods: ['GET'])] public function index(MembreRepository $membreRepository): Response { $membres = $membreRepository->findAll(); return $this->render('membre/index.html.twig', ['membres' => $membres, ]); }
Twig membre/index :
{% extends 'base.html.twig' %}{% block title %}Liste des membres{% endblock %}{% block body %}<h1>Liste des membres</h1><table class="table"><thead><tr><th>Id</th><th>email</th><th>roles</th></tr></thead><tbody> {% for membre in membres %}<tr><td>{{ membre.id }}</td><td>{{ membre.email }}</td> {% for role in membre.roles %}<td>{{ role }}</td><td><a href="{{ path('app_membre_show', {'id' : membre.id}) }}"> Voir la fiche du membre </a></td> {{ dump(membre.id) }} {{ dump('test') }} {# Vérifiez si 'test' s'affiche dans la barre de débogage #}<td><a href="{{ path('app_showroom_index', {'membre_id': membre.id}) }}">Voir les showrooms</a></td> {% endfor %}</td></tr> {% endfor %}</tbody></table>{% endblock %}
twig showroom/index :
{% extends 'base.html.twig' %}{% block title %}Showroom index{% endblock %}{% block body %}<h1>Showroom index</h1><table class="table"><thead><tr><th>Id</th><th>Description</th><th>Publiee</th><th>actions</th></tr></thead><tbody> {% for showroom in showrooms %}<tr><td>{{ showroom.id }}</td><td>{{ showroom.description }}</td><td>{{ showroom.publiee ? 'Yes' : 'No' }}</td><td><a href="{{ path('app_showroom_show', {'id': showroom.id}) }}">show</a><a href="{{ path('app_showroom_edit', {'id': showroom.id}) }}">edit</a></td></tr> {% else %}<tr><td colspan="4">no records found</td></tr> {% endfor %}</tbody></table><a href="{{ path('app_showroom_new') }}">Create new</a>{% endblock %}
I tried to remove the dependency of the member id in the showroom index route but without success.