2017-05-22 12:33
浏览 74


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.

图片转代码服务由CSDN问答提供 功能建议

我使用的是Symfony,需要与我的数据库中的变量进行比较,名为 $ voorraad , <代码> $ minimumvoorraad 。 当 $ voorraad 低于 $ minimumvoorraad 时,我需要查看该产品。 由于我使用的是Symfony,因此我们使用PHP语言。 我已经尝试了 FindByVoorrad FindOneBy 语句但没有成功,我只从我的树枝上得到了标题,但就是这样。


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanmei1885 2017-05-22 12:57

    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:

        {% for product in products %}
                <td>{{ }}</td>
                <td>{{ product.voorraad }}</td>
                <td>{{ product.minimumvoorraad }}</td>
        {% endfor %}
    解决 无用
    打赏 举报

相关推荐 更多相似问题