Sonata admin bundle:showMapper中的order entity字段

时间:2017-08-18 14:41:10

标签: symfony sonata-admin

我正在使用Sonata管理包在Symfony项目的开发中搜索解决方案。

2个实体:联系人和标签(ManyToMany Relationship)

在sonata admin(标签实体)的showaction中,我无法订购联系人字段。如果我在字段中使用查询选项,则无关紧要。我在创建表单中使用了查询选项,查询工作得很好,项目在选择字段中排序。

这可行(创建表单)

    protected function configureFormFields(FormMapper $formMapper)
{
    $TagsQuery = $this->modelManager

        ->getEntityManager('TelRegBundle:Tags')
        ->createQuery(
            'SELECT t
             FROM TelRegBundle:Tags t
             ORDER BY t.title ASC'
        );       

    $formMapper
          //...

            ->add('tags', 'sonata_type_model', array(
                'class' => 'TelRegBundle\Entity\Tags',                    
                'property' => 'title',
                'multiple' => true,
                'query' => $TagsQuery,
            ))

如果相同的方法不起作用(显示行动):

    protected function configureShowFields(ShowMapper $showMapper)
{      

    $showMapper
        ->with('Tags data')
            ->add('title')
        ->end()
        ->with('Contacts')
            ->add('contacts', 'entity', array(
                'class' => 'TelRegBundle:Contacts',
                'associated_property' => 'title',

                'query' => ...  //Querybuilder not working.

                ))
        ->end()                
   ;
}

任何可以提供帮助的人? THX!

1 个答案:

答案 0 :(得分:0)

您只能设置annotation

localhost