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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化