• <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>

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

        how to get the type of a doctrine entity property(如何获取学说实体属性的类型)

      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
                  }
                  

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

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                  <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>
                      <tbody id='jIlGF'></tbody>
                    <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>
                      • <small id='jIlGF'></small><noframes id='jIlGF'>