• <bdo id='oWkN9'></bdo><ul id='oWkN9'></ul>

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

    <tfoot id='oWkN9'></tfoot>

      1. <i id='oWkN9'><tr id='oWkN9'><dt id='oWkN9'><q id='oWkN9'><span id='oWkN9'><b id='oWkN9'><form id='oWkN9'><ins id='oWkN9'></ins><ul id='oWkN9'></ul><sub id='oWkN9'></sub></form><legend id='oWkN9'></legend><bdo id='oWkN9'><pre id='oWkN9'><center id='oWkN9'></center></pre></bdo></b><th id='oWkN9'></th></span></q></dt></tr></i><div id='oWkN9'><tfoot id='oWkN9'></tfoot><dl id='oWkN9'><fieldset id='oWkN9'></fieldset></dl></div>
      2. <legend id='oWkN9'><style id='oWkN9'><dir id='oWkN9'><q id='oWkN9'></q></dir></style></legend>
      3. 如何在 Symfony 2 和 Doctrine 中过滤实体对象内的数据

        How filter data inside entity object in Symfony 2 and Doctrine(如何在 Symfony 2 和 Doctrine 中过滤实体对象内的数据)

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

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

              <tbody id='PED9x'></tbody>
            • <tfoot id='PED9x'></tfoot>

              • <bdo id='PED9x'></bdo><ul id='PED9x'></ul>
                1. <small id='PED9x'></small><noframes id='PED9x'>

                  本文介绍了如何在 Symfony 2 和 Doctrine 中过滤实体对象内的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个实体:ProductFeature.Product 有许多其他 Features(一对多的关系).每个Feature 都有一个名称和一个重要的状态(如果特性重要则为真,否则为假).我想在 TWIG 中使用我的产品的所有重要功能.

                  I have two entities: Product and Feature. Product has many other Features (relation one to many). Every Feature has a name and an important status (true if feature is important, false if not). I want to get in TWIG all important features for my product.

                  下面的解决方案非常难看:

                  Solution below is very ugly:

                  Product: {{ product.name }}
                  Important features:
                  {% for feature in product.features %}
                      {% if feature.important == true %}
                          - {{ feature.name }}
                      {% endif %}
                  {% endfor %}
                  

                  所以我想得到:

                  Product: {{ product.name }}
                  Important features:
                  {% for feature in product.importantFeatures %}
                       - {{ feature.name }}
                  {% endfor %}
                  

                  我必须过滤实体对象中的数据,但如何过滤?

                  I must filter data in entity object, but how?

                  // MyBundle/Entity/Vehicle.php
                  class Product {
                      protected $features; // (oneToMany)
                      // ...
                      protected getFeatures() { // default method
                          return $this->features;
                      }
                      protected getImportantFeatures() { // my custom method
                          // ? what next ?
                      }
                  }
                  
                  // MyBundle/Entity/Feature.php
                  class Feature {
                      protected $name;      // (string)
                      protected $important; // (boolean)
                      // ...
                  }
                  

                  推荐答案

                  您可以使用 Criteria 类过滤掉相关特征的Arraycollection

                  You can use Criteria class to filter out the Arraycollection of related features

                  class Product {
                      protected $features; // (oneToMany)
                      // ...
                      protected getFeatures() { // default method
                          return $this->features;
                      }
                      protected getImportantFeatures() { // my custom method
                          $criteria = DoctrineCommonCollectionsCriteria::create()
                                      ->where(DoctrineCommonCollectionsCriteria::expr()->eq("important", true));
                       return $this->features->matching($criteria);
                      }
                  }
                  

                  在树枝中

                  Product: {{ product.name }}
                  Important features:
                  {% for feature in product.getImportantFeatures() %}
                       - {{ feature.name }}
                  {% endfor %}
                  

                  这篇关于如何在 Symfony 2 和 Doctrine 中过滤实体对象内的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

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

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

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

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