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

  • <tfoot id='fFqR5'></tfoot>
    1. <small id='fFqR5'></small><noframes id='fFqR5'>

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

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

        如何在 Doctrine 中设置默认水合器?

        时间:2024-08-15
        <tfoot id='t4K7R'></tfoot>

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

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

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

                  <tbody id='t4K7R'></tbody>

                  本文介绍了如何在 Doctrine 中设置默认水合器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我找不到在 Doctrine 中设置默认水合器的方法.它应该可用.对吧?

                  I can't find a way to set the default hydrator in Doctrine. It should be available. Right?

                  http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/data-hydrators.html#writing-hydration-method

                  以上文档页面说明了如何创建自定义水合器.这里的缺点是每次执行查询时都需要指定"水合器.

                  The above documentation page explains how to create a custom hydrator. The drawback here is that you need to "specify" the hydrator each and every time you execute a query.

                  推荐答案

                  我通过阅读 Chris Gutierrez 的评论并更改了一些东西来解决这个问题.

                  I figured this out by reading Chris Gutierrez's comment and changing some stuff.

                  首先,为 Doctrine_Query 定义一个扩展类.扩展构造函数来定义你自己的补水模式.

                  First, define an extension class for Doctrine_Query. Extend the constructor to define your own hydration mode.

                  class App_Doctrine_Query extends Doctrine_Query
                  {
                      public function __construct(Doctrine_Connection $connection = null,
                          Doctrine_Hydrator_Abstract $hydrator = null)
                      {
                          parent::__construct($connection, $hydrator);
                          if ($hydrator === null) {
                              $this->setHydrationMode(Doctrine::HYDRATE_ARRAY); // I use this one the most
                          }
                      }
                  }
                  

                  然后,在您的引导程序中,告诉 Doctrine 您的新课程.

                  Then, in your bootstrap, tell Doctrine about your new class.

                  Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_QUERY_CLASS, 'App_Doctrine_Query');  
                  

                  Chris Gutierrez 为连接而不是全局定义了属性,但我有多个连接,我想为所有连接使用此默认值.

                  Chris Gutierrez defined the attribute for the connection instead of globally but I have more than one connection and I want to use this default for all of them.

                  现在您不必每次构建查询时都调用 Doctrine_Query::setHydrationMode().

                  Now you don't have to call Doctrine_Query::setHydrationMode() every time you build a query.

                  这里有更多信息
                  http://www.学说项目.org/projects/orm/1.2/docs/manual/configuration/en#configure-query-class

                  以下更改

                  我发现上面有问题.具体来说,执行Doctrine_Core::getTable('Model')->find(1)"之类的操作将始终返回水合数组,而不是对象.所以我对此做了一些改动,定义了自定义执行方法以在 Query 调用中使用.

                  I have found a problem with the above. Specifically, doing something like "Doctrine_Core::getTable('Model')->find(1)" will always return a hydrated array, not an object. So I have altered this a bit, defining custom execute methods for use in a Query call.

                  另外,我添加了内存释放代码.

                  Also, I added memory freeing code.

                  class App_Doctrine_Query extends Doctrine_Query
                  {
                      public function rows($params = array(), $hydrationMode = null)
                      {
                          if ($hydrationMode === null)
                              $hydrationMode = Doctrine_Core::HYDRATE_ARRAY;
                          $results = parent::execute($params, $hydrationMode);
                          $this->free(true);
                          return $results;
                      }
                  
                      public function row($params = array(), $hydrationMode = null)
                      {
                          if ($hydrationMode === null)
                              $hydrationMode = Doctrine_Core::HYDRATE_ARRAY;
                          $results = parent::fetchOne($params, $hydrationMode);
                          $this->free(true);
                          return $results;
                      }
                  }
                  

                  这篇关于如何在 Doctrine 中设置默认水合器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 yml 映射的实体中配置 VichUploader? 下一篇:Doctrine 向 DQL 的 NEW 构造函数发送一个实体

                  相关文章

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

                    <tfoot id='rIAXe'></tfoot>

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

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

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