Symfony 自定义Sonata管理包的导出CSV内容

Symfony 自定义Sonata管理包的导出CSV内容,symfony,csv,export,sonata-admin,Symfony,Csv,Export,Sonata Admin,我是索纳塔的新手。现在,我正在尝试导出一个csv文件,其中包含:“customer.phone”、“order.total”。。。但当我打开csv文件时,字段“order.total”仅为“99.99”,我想将其导出为“AUD$99.99”,有人知道我如何实现它吗?非常感谢!代码如下: public function getExportFields() { return array('id','customer.First_name','customer.Last_name',

我是索纳塔的新手。现在,我正在尝试导出一个csv文件,其中包含:“customer.phone”、“order.total”。。。但当我打开csv文件时,字段“order.total”仅为“99.99”,我想将其导出为“AUD$99.99”,有人知道我如何实现它吗?非常感谢!代码如下:

public function getExportFields() {
    return array('id','customer.First_name','customer.Last_name',
        'customer.contact','total_amount'
        );
}

您需要在
Order
类中定义方法
getTotalAmountFormatted
,并使其返回您需要的字符串。然后在从
getExportFields

public function getExportFields() {
    return array('id','customer.First_name','customer.Last_name',
        'customer.contact','totalAmountFormated'
        );
}

只需添加,您可以自定义每列的标题,如下所示:

public function getExportFields() {
    return array(
      'Id' => 'id',
      'Customer First Name' => 'customer.First_name',
      'Customer Last Name' => 'customer.Last_name',
      'Customer Contact' => 'customer.contact',
      'Total Amount' => 'totalAmountFormated'
    );
}

谢谢你的回复@tiriana。没错,但是我发现我不确定如何从这个格式中检索'total_amount'的值,换句话说,我不确定如何获取order对象并获取order.getTotal()要存储该值,我尝试了->getSubject()类似的方法,但返回了无对象错误的异常。请看我的更新。不能在exportAction中使用getSubject,因为它不在单个实例上操作,而是在列表集合上操作。因此getSubject在导出中返回null。相反,您需要通知管理员在迭代该集合时应该查找什么属性。如果你对property_path不满意,我建议你看看PropertyAcces组件,明白你的意思了。谢谢。