我试图在网上搜索这个问题的一个明确的解决方案,但那里的新手确实没有具体的解决方案。
我有一个条目有很多EntryListing。 在我的EntryAdmin listMapper中,我可以轻松地按语句列出条目
->add('listings')
它只返回EntryListing __toString()函数中定义的列表。
有没有办法通过覆盖getExportFields()函数导出数据时实现相同的方法,如下所示:
public function getExportFields()
{
return array('name','tel','email','deviceType','postedOn','createdAt','facilitator','listings');
}
非常感谢您的帮助
还有另外一个工作可以在你的实体中添加一个属性,它将获得与之相关的所有条目列表,并在getter函数中返回相关的__toString()
,我有相同的订单方案,如果产品与之关联,还需要列表订购,所以我通过在orders
实体中创建exportProducts
这样做
protected $exportProducts;
public function getExportProducts()
{
$exportProducts = array();
$i = 1;
foreach ($this->getItems() as $key => $val) {
$exportProducts[] = $i .
') Name:' . $val->getProduct()->__toString()() .
' Size:' . $val->getProductsize() .
.../** Other properties */;
$i++;
}
return $this->exportProducts = join(' , ', $exportProducts);
}
在admin类中,我在getExportFields()
定义了exportProducts
属性
public function getExportFields(){
return array(
'Products'=>'exportProducts',
....// Other properties
);
}
在下载的csv中,每个订单都包含Products
单元格下的Products
列表,以逗号分隔列表