2014-10-04 119 views
5

我试过在网上搜索这个问题的确切解决方案,但真的没有具体解决方案给那里的新手。在奏鸣曲上导出一对多关系admin

我有一个条目,其中有很多EntryListing。在我EntryAdmin listMapper,我舒适地可以列出作为

->add('listings') 

仅返回作为EntryListing __toString()函数定义的列表一样简单的声明条目。

有没有办法通过overiding的getExportFields()函数如下导出数据时要达到相同的:

public function getExportFields() 
{ 
    return array('name','tel','email','deviceType','postedOn','createdAt','facilitator','listings'); 
} 

您的帮助将是非常赞赏

回答

7

还有另外一个工作,你身边可以在你的实体中添加一个属性,该属性将获得与该相关的所有条目列表,并且在相关函数的返回__toString()中,我拥有相同的订单场景,并且如果与订单相关的产品也需要列表,所以我已经以此方式完成通过在中创建exportProducts 0实体

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); 
} 

而且为了管理类别i中getExportFields()定义exportProducts属性作为

public function getExportFields(){ 
    return array(
     'Products'=>'exportProducts', 
     ....// Other properties 
     ); 
} 

在下载的CSV每个订单包含下Products细胞产品的列表作为逗号分隔的列表