Exporting one of many relationships to sonata admin

I tried to search the Internet for a specific solution to this issue, but there really is no specific solution for beginners.

I have an entry in which there are a lot of input elements. In my EntryAdmin listMapper element, I can comfortably write entries using an instruction as easy as

->add('listings') 

which simply returns lists as defined in the EntryListing __toString () function.

Is there a way to achieve this when exporting data by overriding the getExportFields () functions, as shown below:

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

Your help will be much appreciated.

+5
source share
1 answer

There is one more work around, you can add a property to your object, which will receive all the entry entries related to this, and in the getter return __toString() related functions, I had the same script for orders, and I also need a list of if products related to order, so I did it this way by creating exportProducts in orders entity

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

And for the admin class, I defined the exportProducts property in getExportFields() as

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

In the loaded csv, each order contains a list of products in the Products cell as a comma separated list

+7
source

Source: https://habr.com/ru/post/1203985/


All Articles