1. <small id='j5siI'></small><noframes id='j5siI'>

    <tfoot id='j5siI'></tfoot>

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

    1. <legend id='j5siI'><style id='j5siI'><dir id='j5siI'><q id='j5siI'></q></dir></style></legend>

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

      Symfony/Doctrine - createQueryBuilder orderBy

      时间:2023-08-18
        <tbody id='EIBYK'></tbody>

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

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

              1. <tfoot id='EIBYK'></tfoot>
              2. <legend id='EIBYK'><style id='EIBYK'><dir id='EIBYK'><q id='EIBYK'></q></dir></style></legend>
                <i id='EIBYK'><tr id='EIBYK'><dt id='EIBYK'><q id='EIBYK'><span id='EIBYK'><b id='EIBYK'><form id='EIBYK'><ins id='EIBYK'></ins><ul id='EIBYK'></ul><sub id='EIBYK'></sub></form><legend id='EIBYK'></legend><bdo id='EIBYK'><pre id='EIBYK'><center id='EIBYK'></center></pre></bdo></b><th id='EIBYK'></th></span></q></dt></tr></i><div id='EIBYK'><tfoot id='EIBYK'></tfoot><dl id='EIBYK'><fieldset id='EIBYK'></fieldset></dl></div>
                本文介绍了Symfony/Doctrine - createQueryBuilder orderBy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个带有属性预算"的团队"实体.我只想打印团队属性,我希望预算最大的团队出现在第一、第二、第三......(DESC).

                I have a 'Team' Entity with a property 'budget'. I just want to print the teams properties and i want that the team with the biggest budget appear in first position, the second, the third... (DESC).

                但是使用此代码,它不起作用,我不明白为什么.

                But with this code, it does not work and i don't understand why.

                indexAction(控制器)

                    $em = $this->getDoctrine()->getManager();
                    $teams = $em->getRepository('FootballBundle:Team')->getAllTeamsSortedByDescBudget();
                
                
                    return $this->render('FootballBundle:Default:index.html.twig', array(
                        'teams' => $teams,
                    ));
                

                团队存储库

                public function getAllTeamsSortedByDescBudget()
                {
                    $q = $this->createQueryBuilder('a');
                    $q->select()->from('FootballBundle:Team', 't')->orderBy('t.budget', 'DESC');
                
                    return $q->getQuery()->getResult();
                }
                

                树枝视图

                <h1>Teams list</h1>
                <ul>
                    {% for team in teams  %}
                        <li>{{ team.name }} - {{ team.championship }} - {{ team.budget|number_format(2, '.', ',') }}</li>
                    {% endfor  %}
                    <br/>
                </ul>
                

                Team.php 实体

                /**
                 * @var integer
                 *
                 * @ORMColumn(name="budget", type="integer")
                 */
                private $budget;
                

                这里,结果......

                And here, the result ...

                Teams list
                
                Manchester City FC - Premier League - 100,000,000.00
                Arsenal FC - Premier League - 50,000,000.00
                Leicester City - Premier League - 20,000,000.00
                Crystal Palace FC - Premier League - 5,000,000.00
                Chelsea FC - Premier League - 100,000,000.00
                

                切尔西...哈哈

                编辑:更正!请参阅takeit 评论.

                EDIT : CORRECTED ! See the takeit comment.

                推荐答案

                getAllTeamsSortedByDescBudget 方法中的 QueryBuilder 查询更改为:

                Change your QueryBuilder query in getAllTeamsSortedByDescBudget method to:

                public function getAllTeamsSortedByDescBudget() 
                { 
                    $qb = $this->createQueryBuilder('t')
                        ->orderBy('t.budget', 'DESC');
                
                    return $qb->getQuery()->getResult(); 
                }
                

                这篇关于Symfony/Doctrine - createQueryBuilder orderBy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:教义 2 中与单个实体的父子关系 下一篇:Doctrine2 ORM 不会刷新在脚本之外更改的对象

                相关文章

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

                1. <small id='B3lFF'></small><noframes id='B3lFF'>

                    <tfoot id='B3lFF'></tfoot>