0

I am very new at programming and especially at symfony. But I tried to make a query to show product that have less VoorraadInAantal than MinimumVoorraad, yet there is nothing showing up.

this is the code I am using to get to try to show the results;

/**
* @Route("/artikel/minimumvoorraad", name="minimumvoorraad")
*/
Public function indexAction(){
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT a
FROM AppBundle:Artikel a
WHERE a.minimumVoorraad > a.voorraadInAantal'

);
$artikelen = $query->getResult();
return new Response($this->render('minimumvoorraad.html.twig', 
array('artikelen' => $artikelen)));

}

twig:

{% extends 'base.html.twig' %}
{% block body %}
<h1>Overzicht Artikelen</h1>
<h2><a href="{{ path('nieuwartikel',{}) }}">Nieuw Artikel</a></h2>
<ul>
{% for artikel in artikelen %}
        <li style="color:darkgreen; float:left"> 
            Artikelnummer: {{artikel.artikelnummer}} <br>
            Omschrijving: {{artikel.omschrijving}} <br>
            MinimumVoorraad: {{artikel.minimumVoorraad}} <br>
            VoorraadInAantal: {{artikel.voorraadInAantal}} <br>
            Bestelserie: {{artikel.bestelserie}} <br>

            <a href="{{ path('artikelwijzigen',{'artikelnummer':artikel.artikelnummer}) }}">Wijzig</a>
            <a href="{{ path('artikelverwijderen',{'artikelnummer':artikel.artikelnummer}) }}">Verwijder uit assortiment</a>
            <br>
    </li>
{% endfor %}
<ul>
{% endblock %}

Maybe I forgot something? This could be very much the case.

Colin
  • 21
  • 2
  • 9
  • You don't need to `return new Response($this->render(...));` as `$this->render` already returns a response. So just use `return $this->render(...);` in your controllers. See [the answer to one of your previous questions](https://stackoverflow.com/questions/44161375/symfony-the-controller-must-return-a-response), the "edit for clarification" in particular. – ccKep May 25 '17 at 15:05
  • Also, you should decouple your queries from your controllers and put them into a separate repository class. See [this article](http://symfony.com/doc/current/doctrine/repository.html) on how that's done. – ccKep May 25 '17 at 15:07

0 Answers0