带有集合字段的奏鸣曲管理员导出字段 [英] Sonata admin export fields with collection fields
问题描述
我正在尝试制作用于导出的自定义列,但我无法访问子项.有没有可能做到这一点?
I'm trying to make custom columns for export, but I can't access children. Is there any possibility to do that ?
我现在的代码是这样的:
My code at this moment looks like this:
public function getExportFields()
{
return [
'ID' => 'id',
'Transaction number' => 'transactionNumber',
'Loan account' => 'loan',
'Loan name' => 'loan.name',
'Amount' => 'amount',
//'Amount ($)' => '',
'Transaction type' => 'transactionCategory',
'Reference' => 'transactionAssociation.cashTransaction.transactionNumber',
'Date' => 'date'
];
}
我找不到解决方案.我想使用 PropertyAccess,但我不知道如何在此处集成.
I can't find out a solution. I was thinking to use PropertyAccess, but I don't know how to integrate it here.
我将 Symfony 3.X 与 Sonata 一起使用.
I'm using Symfony 3.X with Sonata.
推荐答案
要在导出中获取集合记录,您不能通过指定具有关联的属性直接执行此操作,要实现此目的的解决方法,您可以在您的实体具有 getter 函数,它将获取所有集合详细信息,例如在您的主实体中将新属性定义为
To get the collection records in export you cannot directly do this by specifying the property with association, A workaround for to achieve this you can define a new unmapped property in your entity with a getter function which will get all the collection details like in your main entity define new property as
protected $cashTransactionNumber;
public function getCashTransactionNumber()
{
$cashTransactionNumber = array();
$i = 1;
foreach ($this->getTransactionAssociation() as $key => $transactionAssociation) {
$cashTransactionNumber [] = $i .
') No.:' . $transactionAssociation->somemethod()->__toString()() .
/** Other properties */;
$i++;
}
return $this->cashTransactionNumber = join(' , ', $cashTransactionNumber );
}
然后在您的 getExportFields()
方法中调用此属性
then in your getExportFields()
method call this property
public function getExportFields(){
return array(
'Reference'=>'cashTransactionNumber ',
....// Other properties
);
}
这篇关于带有集合字段的奏鸣曲管理员导出字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!