doushangxianq07480 2012-11-23 14:47
浏览 41
已采纳

Sonata admin - “order by”对Entity不起作用

I can't make to work a entity sorting in the sonata admin listing, here is my entity:

class User extends BaseUser {
/**
* @ORM\ManyToOne(targetEntity="Region", inversedBy="users")
*/
protected $preferredRegion;
}

And here is the configureListFields definition:

 protected function configureListFields(ListMapper $listMapper) {
     $listMapper->add('preferredRegion', NULL, array('label' => 'Preferred Region',  'sortable' => 'preferredRegion'))
 }

When clicking on the table head column to sort it by my entity name I get this error:

An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 25 near 'AS __order_by': Error: Entity\User has no field or association named AS")

How can I make this sort to work for the entity so it sorts alphabetically by my entity name?

Thank you

Julian Mancera

  • 写回答

1条回答 默认 最新

  • dongshuo8756 2012-11-23 18:38
    关注

    Try:

    $listMapper->add('preferredRegion.id', NULL, array('label' => 'Preferred Region'));
    

    If that works, instead of .id you can put .title, .name of some other column in that table.

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

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程