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 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥15 抖音看过的视频,缓存在哪个文件