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

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

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

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

        如何获取学说实体属性的类型

        时间:2023-08-18

      2. <legend id='OjWMu'><style id='OjWMu'><dir id='OjWMu'><q id='OjWMu'></q></dir></style></legend>
          <bdo id='OjWMu'></bdo><ul id='OjWMu'></ul>

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

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

                • 本文介绍了如何获取学说实体属性的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  实际上我有一个学说实体,我需要动态填充其属性.

                  Actually I have a doctrine entity that I need to fill its prperties dynamically.

                  我希望能够做这样的事情:

                  I'd like to be able to do something like this:

                  $entity = new Entity();
                  $reflect = new ReflectionClass($entity);
                  // $fields is an array whihch contain the entity name as the array key and the value as the array value
                  foreach ($fields as $key => $val)
                  {
                      if (!reflect->hasProperty($key)) {
                          var_dump('the entity does not have a such property');
                          continue;
                      }
                      if ( the type of $key is string ) {
                            // convert $value to utf8
                      } elseif ( the type of $key is integer) {
                            // do something else
                      } //....etc
                  }
                  

                  我该怎么做?

                  推荐答案

                  Found 感谢@Yoshi 的解决方案.希望能帮到你

                  Found the solution thanks to @Yoshi. I hope it'll help

                  use DoctrineCommonAnnotationsAnnotationReader;
                  
                  $docReader = new AnnotationReader();
                  $entity = new Entity();
                  $reflect = new ReflectionClass($entity);
                  // $fields is an array whihch contain the entity name as the array key and the value as the array value
                  foreach ($fields as $key => $val)
                  {
                      if (!reflect->hasProperty($key)) {
                          var_dump('the entity does not have a such property');
                          continue;
                      }
                      $docInfos = $docReader->getPropertyAnnotations($reflect->getProperty($key));
                      if ( $docInfos[0]->type === 'string' ) {
                            // convert $value to utf8
                      } elseif ( $docInfos[0]->type === 'integer' ) {
                            // do something else
                      } //....etc
                  }
                  

                  这篇关于如何获取学说实体属性的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将 ZendOpCache 用于 Doctrine2 缓存? 下一篇:findBy 与 Symfony2 中的 JOIN 条件

                  相关文章

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

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