2014-10-04 107 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細胞產品的列表作爲逗號分隔的列表