• <tfoot id='ltSL5'></tfoot>

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

      <bdo id='ltSL5'></bdo><ul id='ltSL5'></ul>

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

        不调用具有抽象基类的 Doctrine 2 LifecycleCallbacks

        Doctrine 2 LifecycleCallbacks with abstract base class are not called(不调用具有抽象基类的 Doctrine 2 LifecycleCallbacks)
      1. <small id='jW9Nk'></small><noframes id='jW9Nk'>

                <tbody id='jW9Nk'></tbody>

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

                <bdo id='jW9Nk'></bdo><ul id='jW9Nk'></ul>
                1. <tfoot id='jW9Nk'></tfoot>
                  本文介绍了不调用具有抽象基类的 Doctrine 2 LifecycleCallbacks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这种情况:

                  抽象类:

                  abstract class AbstractBase
                  {
                      /**
                       * @ORMId
                       * @ORMGeneratedValue
                       * @ORMColumn(type="integer")
                       * @var integer
                       */
                      protected $id;
                  
                      /**
                       * @ORMColumn(type="datetime", name="updated_at")
                       * @var DateTime $updatedAt
                       */
                      protected $updatedAt;
                  
                      /**
                       * @ORMPreUpdate
                       */
                      public function setUpdatedAt()
                      {
                          die('THIS POINT IS NEVER REACHED');
                          $this->updatedAt = new DateTime();
                      }
                  }
                  

                  具体类:

                  /**
                   * @ORMEntity(repositoryClass="EntityRepositoryUserRepository")
                   * @ORMTable(name="users")
                   * @ORMHasLifecycleCallbacks
                   */
                  class User extends AbstractBase
                  {
                      // some fields, relations and setters/getters defined here, these all work as expected.
                  }
                  

                  然后我像这样在我的控制器中调用它:

                  Then i call it in my controller like this:

                  $user = $this->em->find('EntityUser', 1);
                  // i call some setters here like $user->setName('asd');
                  $this->em->flush();
                  die('end');
                  

                  一切都按预期工作,因此抽象类中的 id 字段为 User 实体创建,我可以访问它等.问题是,永远不会到达死('这个点从未达到')"这一行.(注意@ORMPreUpdate)这意味着不会调用lifecycleCallbacks继承的对象.这是一个错误,还是有原因?

                  Everything works as expected, so the id field from the abstract class gets created for the User entity, i can access it etc. The problem is, that the line "die('THIS POINT IS NEVER REACHED')" is never reached. (Note the @ORMPreUpdate) This means that lifecycleCallbacks are not called on inherited objects. Is this a bug, or is there a reason for this?

                  推荐答案

                  您的抽象基类必须被注释为映射超类,并包含 HasLifecycleCallbacks-注释.

                  Your abstract base class has to be anotated as Mapped Superclasses and include the HasLifecycleCallbacks-Annotation.

                  更多信息:教义文档中的继承映射.

                  /**
                   * @ORMMappedSuperclass
                   * @ORMHasLifecycleCallbacks
                   */
                  abstract class AbstractBase
                  {
                      [...]
                  
                      /**
                       * @ORMPreUpdate
                       */
                      public function setUpdatedAt()
                      {
                          $this->updatedAt = new DateTime();
                      }
                  }
                  
                  /**
                   * @ORMEntity(repositoryClass="EntityRepositoryUserRepository")
                   * @ORMTable(name="users")
                   */
                  class User extends AbstractBase
                  {
                      // some fields, relations and setters/getters defined here, these all work as expected.
                  }
                  

                  这篇关于不调用具有抽象基类的 Doctrine 2 LifecycleCallbacks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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() 函数)

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

                    1. <tfoot id='SKObj'></tfoot>
                        <tbody id='SKObj'></tbody>

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

                          <bdo id='SKObj'></bdo><ul id='SKObj'></ul>
                            <legend id='SKObj'><style id='SKObj'><dir id='SKObj'><q id='SKObj'></q></dir></style></legend>