I am using Symfony and need to compare to variables from my database called $voorraad
and $minimumvoorraad
. I need to see the product when $voorraad
is lower than $minimumvoorraad
. Since I am using Symfony we use the PHP language. I've tried the FindByVoorrad
and FindOneBy
statements with no success, I only get the header from my twig but that's it.
Thanks in advance.
Given your Entity consists of whatever fields including 'voorraad' and 'minimumvoorraad', you should be able to get your database table's content via
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT e
FROM AppBundle:Entity e
WHERE e.voorraad < e.minimumvoorraad'
);
$products = $query->getResult();
Edit: the e in the query is a SQL-typical alias defined inline.
And then treat your $products variable as usual, where you can use all of your getters and setters.
After rendering and passing your products to the Twig view
return $this->render('view.html.twig', array(
'products' => $products
));
you could then proceed to print the products, for example, in a table inside your Twig view:
<table>
{% for product in products %}
<tr>
<td>{{ product.id }}</td>
<td>{{ product.voorraad }}</td>
<td>{{ product.minimumvoorraad }}</td>
</tr>
{% endfor %}
</table>