<legend id='1ZMGO'><style id='1ZMGO'><dir id='1ZMGO'><q id='1ZMGO'></q></dir></style></legend>

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

        • <bdo id='1ZMGO'></bdo><ul id='1ZMGO'></ul>

        如何在 symfony2 中使用学说 findOneBy 方法返回数组而不是对象?

        时间:2024-08-15
        • <tfoot id='YcN7X'></tfoot>
        • <legend id='YcN7X'><style id='YcN7X'><dir id='YcN7X'><q id='YcN7X'></q></dir></style></legend>

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

                    <tbody id='YcN7X'></tbody>

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

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

                  本文介绍了如何在 symfony2 中使用学说 findOneBy 方法返回数组而不是对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一种情况,我想使用 symfony2 中的学说中的 findOneBy($id) 方法查询数据库.

                  I have a situation in which I want to query the database with findOneBy($id) method from doctrine in symfony2.

                  $namePosting = $this->getDoctrine()->getRepository('MyBundle:Users')->findOneById($userPosting);
                  

                  结果它是一个具有受保护属性的对象.我想直接返回一个数组.如何才能做到这一点 ?

                  The result it's an object with protected properties. I want to return it directly an array. How can this be done ?

                  推荐答案

                  findOneBy(array()) 将始终返回 null 或 object.

                  findOneBy(array()) will always return null or object.

                  但您可以使用 findById($userPosting)findBy(array('id' => $userPosting)) 来代替它,它会返回一个数组,例如:

                  But you can use instead findById($userPosting) or findBy(array('id' => $userPosting)) and it will return an array, e.g.:

                  $this->getDoctrine()->getRepository('MyBundle:Users')->findById($userPosting))
                  

                  已编辑

                  或者你可以在 UserRepository 类中添加一个方法:

                      use DoctrineORMEntityRepository;
                      use DoctrineORMQuery;
                  
                      class UserRepository extends EntityRepository
                      { 
                          public function getUser($userPosting)
                          {
                             $qb = $this->createQueryBuilder('u')
                               ->select('u')
                               ->where('u =:userPosting')->setParameter('userPosting', $userPosting)
                               ->getQuery()
                               ->getResult(Query::HYDRATE_ARRAY);
                  
                             return $qb;
                          }   
                      }
                  

                  这篇关于如何在 symfony2 中使用学说 findOneBy 方法返回数组而不是对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Doctrine Join 条件类型中的 WITH 和 ON 有什么区别? 下一篇:Symfony 2 - 试图调用函数“apcu_fetch"来自命名空间“DoctrineCommonCach

                  相关文章

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

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

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

                      <tfoot id='t5Z1T'></tfoot>