Partage
  • Partager sur Facebook
  • Partager sur Twitter

récupérer données twig

    22 septembre 2021 à 12:46:05

    Bonjour je travail actuellement sur un site de maquillage et j'ai donc pleins de sous catégories avec des jointures,

    j'ai cependant un problème (encore) pour récupérer ID du Makeup en question pour m'afficher une page, je m'explique :

    /**
         * @param MakeupProductsRepository $makeupProductRepository
         * @param int $makeup_product_id
         * @return Response
         * @Route("/ref/{makeup_product_id}", name="ref")
         */
        public function showProductRef(MakeupProductsRepository $makeupProductRepository, int $makeup_product_id): Response
        {
            $makeupProduct = $makeupProductRepository->find(['id' => $makeup_product_id]);
    
            return $this->render('makeup_home/makeupRef.html.twig',
                ['makeupProductsRef' => $makeupProduct->getMakeupRefs(),
                ]);
        }

    le controller de la page en question et ci dessous son code :

    {% extends 'layout.html.twig' %}
    
    {% block main %}
    
        <div class="makeupContainer container d-flex mx-auto text-center row">
    
            {% for makeupRefDetails in makeupProductsRef  %}
                {% if makeupRefDetails.name == "palette 3 couleurs" %}
                    {# break #}
                    <div class="card col-lg-4 mt-5" style="width: 18rem;">
                        <a href="{{ path('makeup_colours', {'makeup_product_id': makeupRefDetails.id}) }}">
                            <div class="card-body">
                                <p class="card-body">test</p>
                            </div>
                        </a>
                    </div>
                {% endif %}
            {% endfor %}
    
            {% for makeupRefDetails in makeupProductsRef %}
                <div class="card col-lg-4 mt-5" style="width: 18rem;">
                    <a href="{{ path('makeup_refDetails', {'makeup_ref_id': makeupRefDetails.id}) }}">
                        <div class="card-body">
                            <p class="card-body">{{ makeupRefDetails.name }}</p>
                        </div>
                    </a>
                </div>
            {% endfor %}
        </div>
    {% endblock %}

    sur la première boucle j'ai 

                        <a href="{{ path('makeup_colours', {'makeup_product_id': makeupRefDetails.id}) }}">
    

    devant m'emmener à cette page :

    /**
         * @param MakeupProductsRepository $makeupProductsRepository
         * @param int $makeup_product_id
         * @return Response
         * @Route("/D/{makeup_product_id}", name="colours")
         */
        public function showProductColoursAndPackagings(MakeupProductsRepository $makeupProductsRepository, int $makeup_product_id): Response
        {
            $makeupColoursDetails = $makeupProductsRepository->find(['id' => $makeup_product_id]);
    
            return $this->render('makeup_home/makeupColoursAndPackagings.html.twig',
                ['makeupColoursDetails' => $makeupColoursDetails->getColours(),
                ]);
        }

    sauf que je ne récupère pas l'id du makeup ici 4 mais l'id de ma sous catégories.

    je devrais faire quelque chose comme 

                        <a href="{{ path('makeup_colours', {'makeup_product_id': makeupRefDetails.MAKEUP_ID}) }}">
    

    Mais ça ne marche pas, je me creuse la tete depuis deux jours maintenant et je suis sur qu'il y'a un moyen simple de le faire, sachant que j'ai l'id voulu dans mon URL à savoir "/makeup/ref/4"

    merci pour votre aide à venir 





    • Partager sur Facebook
    • Partager sur Twitter

    récupérer données twig

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown