duanbing6955 2018-09-05 13:32
浏览 49
已采纳

Symfony php错误消息createQueryBuilder添加了一个WHERE

I have moved an app from a PHP5 to a PHP7 server. It runs almost smoothly except with a bug in a query builer creation. I have a form in which I take elements from an entity user and wnated to order them. As you can see I do not have a WHERE in my query:

->add('user', 'entity', array(
                'class' => 'MyappAppliBundle:User',
                'property' => 'name',
                'required' => false,
                'empty_value' => '',
                'empty_data' => null,
                'query_builder' => function (EntityRepository $br) {
                    return $br->createQueryBuilder('qb')
                        ->orderBy('qb.name', 'ASC');
                }

However, when I try to open my form, I have the following error message:

[Syntax Error] line 0, col 55: Error: Expected Literal, got 'ORDER'

SELECT qb FROM Myapp\AppliBundle\Entity\User qb WHERE ORDER BY qb.name AS

I do not understand why there is a WHERE added here!

If I remove the createQueryBuilder, the form appears perfectly (except the users are not sorted), otherwise I have the error message.

If someone would have an idea, that would be great!

Thanks a lot

EDIT: I am using symfony2 (version 2.3.9 to be precise!)

EDIT 2: I have moved to symfony2.7 now and have changed a little bit the add:

->add('user', 'entity', array(
                'class' => 'MyappAppliBundle:User',
                'choice_translation_domain' => true,
                'choice_label' => 'name',
                'required' => false,
                'placeholder' => '',
                'empty_data' => null,
                'query_builder' => function (EntityRepository $br) {
                    return $br->createQueryBuilder('qb')
                        ->orderBy('qb.name', 'ASC');
                }
            ))

However I still have the same issue with this WHERE thats seems coming out of nowhere.

  • 写回答

1条回答 默认 最新

  • dpnfjx755573 2018-09-10 08:25
    关注

    I found the solution. I had

    "doctrine/orm": "2.2.*"
    

    in my composer.json... I modified it to

    "doctrine/orm": ">=2.2.*"
    

    I ran composer update and it updated doctrine/orm to 2.5.14. The problem is now solved!

    Thanks for the help!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器