<i id='jTMkn'><tr id='jTMkn'><dt id='jTMkn'><q id='jTMkn'><span id='jTMkn'><b id='jTMkn'><form id='jTMkn'><ins id='jTMkn'></ins><ul id='jTMkn'></ul><sub id='jTMkn'></sub></form><legend id='jTMkn'></legend><bdo id='jTMkn'><pre id='jTMkn'><center id='jTMkn'></center></pre></bdo></b><th id='jTMkn'></th></span></q></dt></tr></i><div id='jTMkn'><tfoot id='jTMkn'></tfoot><dl id='jTMkn'><fieldset id='jTMkn'></fieldset></dl></div>

<small id='jTMkn'></small><noframes id='jTMkn'>

    1. <legend id='jTMkn'><style id='jTMkn'><dir id='jTMkn'><q id='jTMkn'></q></dir></style></legend>

          <bdo id='jTMkn'></bdo><ul id='jTMkn'></ul>
        <tfoot id='jTMkn'></tfoot>

      1. 如何在学说 2 实体的存储库中使用复杂的标准?

        时间:2023-08-19
        <tfoot id='Lf23E'></tfoot>

            • <legend id='Lf23E'><style id='Lf23E'><dir id='Lf23E'><q id='Lf23E'></q></dir></style></legend>
                <tbody id='Lf23E'></tbody>
                <bdo id='Lf23E'></bdo><ul id='Lf23E'></ul>

                1. <i id='Lf23E'><tr id='Lf23E'><dt id='Lf23E'><q id='Lf23E'><span id='Lf23E'><b id='Lf23E'><form id='Lf23E'><ins id='Lf23E'></ins><ul id='Lf23E'></ul><sub id='Lf23E'></sub></form><legend id='Lf23E'></legend><bdo id='Lf23E'><pre id='Lf23E'><center id='Lf23E'></center></pre></bdo></b><th id='Lf23E'></th></span></q></dt></tr></i><div id='Lf23E'><tfoot id='Lf23E'></tfoot><dl id='Lf23E'><fieldset id='Lf23E'></fieldset></dl></div>
                2. <small id='Lf23E'></small><noframes id='Lf23E'>

                  本文介绍了如何在学说 2 实体的存储库中使用复杂的标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有一张表格,其中包含有关节日的信息.
                  每个节日都有开始和结束日期.

                  Lets say I have a table that holds information about festivals.
                  Each festival has a start and end date.

                  我想选择在给定日期现场(发生)的所有节日.

                  I want to select all the festivals that are live (that happen) on a given date.

                  意思是,我想选择开始日期早于或在给定日期,而结束日期晚于或在同一给定日期的所有节日.

                  Meaning, I want to select all the festivals that their start date is before or on a given date, and that their end date is after or on a the same given date.

                  所以我继续使用节日实体的存储库类,并创建了一个方法来做到这一点.
                  但是标准参数findBy"期望是一个数组,所有示例仅将其视为一个简单的条件(例如,array('name' => 'billy')"将选择名称列中具有值 billy 的所有行),其中仅使用比较运算符.

                  So I went on to the repository class of the festival entity, and created a method to do just that.
                  But the criteria argument "findBy" expects is an array, which all the examples only treat as a simple criteria (e.g. "array('name' => 'billy')" will select all the rows that have the value billy in their name column), which uses only the comparison operator.

                  如何使用其他运算符,例如

                  How can I use other operators such as

                  >, <, !=, IN, NOT IN, LIKE    
                  

                  等等?

                  推荐答案

                  如果您需要特定的查询,则需要编写自己的查询(可能使用 DQL).我相信内置的findBy"方法更适合用于快速抓取对象,如果您的标准不那么具体.我不知道您的实体名称或它们的存储位置.可能是您的 Festival Repository 中的一个函数.

                  You'll need to write your own query (probably using DQL) if you want something that specific. I believe the built in "findBy" methods are more for just grabbing objects quickly if you have less specific criteria. I don't know your entity names or where they are stored. Could be something like this as a function in your Festival Repository.

                  public function findActiveFestivals($start, $end)
                  {
                      $qb = $this->_em->createQueryBuilder();
                      $qb->select('f')
                          ->from('Festival', 'f')
                          ->where('f.start >= :start')
                          ->andWhere('f.end <= :end')
                          ->setParameters(array('start' => $start, 'end' => $end));
                  
                      return $qb->getQuery()->getArrayResult();
                  }
                  

                  这篇关于如何在学说 2 实体的存储库中使用复杂的标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Doctrine QueryBuilder 删除连接 下一篇:使用查询构建器删除 Doctrine 2

                  相关文章

                    <bdo id='CTqiO'></bdo><ul id='CTqiO'></ul>
                  1. <tfoot id='CTqiO'></tfoot>

                      <i id='CTqiO'><tr id='CTqiO'><dt id='CTqiO'><q id='CTqiO'><span id='CTqiO'><b id='CTqiO'><form id='CTqiO'><ins id='CTqiO'></ins><ul id='CTqiO'></ul><sub id='CTqiO'></sub></form><legend id='CTqiO'></legend><bdo id='CTqiO'><pre id='CTqiO'><center id='CTqiO'></center></pre></bdo></b><th id='CTqiO'></th></span></q></dt></tr></i><div id='CTqiO'><tfoot id='CTqiO'></tfoot><dl id='CTqiO'><fieldset id='CTqiO'></fieldset></dl></div>

                      <small id='CTqiO'></small><noframes id='CTqiO'>

                      <legend id='CTqiO'><style id='CTqiO'><dir id='CTqiO'><q id='CTqiO'></q></dir></style></legend>