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

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

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

      1. 教义2关联未初始化

        doctrine2 association is not initialized(教义2关联未初始化)
        <i id='fSV8E'><tr id='fSV8E'><dt id='fSV8E'><q id='fSV8E'><span id='fSV8E'><b id='fSV8E'><form id='fSV8E'><ins id='fSV8E'></ins><ul id='fSV8E'></ul><sub id='fSV8E'></sub></form><legend id='fSV8E'></legend><bdo id='fSV8E'><pre id='fSV8E'><center id='fSV8E'></center></pre></bdo></b><th id='fSV8E'></th></span></q></dt></tr></i><div id='fSV8E'><tfoot id='fSV8E'></tfoot><dl id='fSV8E'><fieldset id='fSV8E'></fieldset></dl></div>
          1. <small id='fSV8E'></small><noframes id='fSV8E'>

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

                  本文介绍了教义2关联未初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个类如下:

                  /** @Entity **/
                  class orgGroup{
                  
                      //id and stuff...
                  
                      /**
                       * @Column(type="string")
                       **/
                      private $name;
                  
                      /**
                       * @Column(type="string", nullable=true)
                       **/
                      private $description;
                  
                      /**
                       * @ManyToOne(targetEntity="orgGroupType", inversedBy="_orgGroups")
                       * @JoinColumn(name="_orgGroupType")
                       **/
                  
                      private $_orgGroupType;
                  
                      //...
                  }
                  

                  但是当我从我的数据库中加载这个对象时

                  But when i load this Object from my database via

                  $groups = $em->getRepository("orgGroup")->findAll();
                  

                  我只是正确地获得了名称,但不是 _orgGroupType...而且我不知道为什么... OrgGroup 是 orgGroupType 的所有者,它只是一个对象而不是数组.我的网络服务总是说:

                  I just get the name correctly but not the _orgGroupType... and i dont know why... OrgGroup is the owner of orgGroupType and its just ONE object and not an array. My Webservice always just says:

                  {"error":[],"warning":[],"message":[],"data":[{"name":"AdministratorGroup","description":null,"_orgGroupType":{"__ isInitialized __":false}}]}
                  

                  结果是:

                  "name":"AdministratorGroup",
                  "description":null,
                  "_orgGroupType":{"__ isInitialized __":false}
                  

                  但应该是:

                  "name":"AdministratorGroup",
                  "description":"some description",
                  "_orgGroupType":{name:"test"}
                  

                  所以有 2 个错误...我不知道为什么.数据库中的所有数据都设置正确.

                  So there are 2 errors... and I have no idea why. All the data is set correctly in the database.

                  有什么想法吗?

                  这是我的 orgGroupType -entity 缺少的代码

                  Here's the missing code of my orgGroupType -entity

                  /** @Entity **/
                  class orgGroupType {
                      /**
                       * @OneToMany(targetEntity="orgGroup", mappedBy="_orgGroupType")
                       **/
                      private $_orgGroups;
                  
                      public function __construct()
                      {
                          $this->_orgGroups = new ArrayCollection();
                      }
                  }
                  

                  推荐答案

                  在我看来,这就像一个延迟加载问题.如何将对象中的数据获取到 Webservice 答案中?

                  This looks to me like a lazy-loading-issue. How do you get the data from the object into the Webservice answer?

                  如果你不配置其他东西,Doctrine2 是延迟加载的,这意味着你的 $groups = $em->getRepository("orgGroup")->findAll(); 不会't 返回真正的 orgGroup 对象,但代理对象(教义文档).

                  Doctrine2 is lazy-loading if you don't configure something else, that means your $groups = $em->getRepository("orgGroup")->findAll(); won't return real orgGroup objects, but Proxy objects (Doctrine Documentation).

                  这意味着 $group 对象在您调用 $group->getDescription()$group- 之前不会有它的描述或 orgGroupType 值>getOrgGroupType()(然后 Doctrine 会自动加载它们),因此您需要在将数据写入 Web 服务的 JSON 响应之前执行此操作.如果您不使用 getter 方法而以某种方式遍历对象属性,它将无法工作.

                  That means a $group object won't have it's description or orgGroupType value until you call $group->getDescription() or $group->getOrgGroupType() (then Doctrine loads them automatically), so you need to do that before writing the data into the JSON-response for the webservice. It won't work if you somehow loop through the object properties without using the getter methods.

                  我希望这是问题所在:)

                  I hope that was the problem :)

                  这篇关于教义2关联未初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)

                    <tfoot id='NOmm9'></tfoot>

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

                          <tbody id='NOmm9'></tbody>

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