Sonata 管理包:showMapper 中的订单实体字段
Sonata admin bundle: order entity field in showMapper
我正在使用 Sonata 管理包在 Symfony 项目中的开发中寻找解决方案。
2 个实体:联系人和标签(多对多关系)
在 sonata admin(标签实体)的 showaction 中,我无法对联系人字段进行排序。我是否在字段中使用查询选项并不重要。我在创建表单中使用了查询选项,查询效果很好,项目在 select 字段中排序。
这个有效(创建表单)
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()
;
}
谁能帮忙?谢谢!
您只能设置annotation
/**
* @ManyToMany(targetEntity="Tags")
* @OrderBy({"title" = "ASC"})
*/
private $tags;
我正在使用 Sonata 管理包在 Symfony 项目中的开发中寻找解决方案。
2 个实体:联系人和标签(多对多关系)
在 sonata admin(标签实体)的 showaction 中,我无法对联系人字段进行排序。我是否在字段中使用查询选项并不重要。我在创建表单中使用了查询选项,查询效果很好,项目在 select 字段中排序。
这个有效(创建表单)
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()
;
}
谁能帮忙?谢谢!
您只能设置annotation
/**
* @ManyToMany(targetEntity="Tags")
* @OrderBy({"title" = "ASC"})
*/
private $tags;