想要在 sonata admin 中更改导出文件的 header

Want to change header of exported file in sonata admin

你好,

我正在开发 symfony sonata admin,我正在使用它的默认导出功能。

我的数据库列名称是电话代码,所以当我导出文件时,header 名称称为电话代码。

我想动态更改它,我不想更改列名称,因为它在项目中随处使用。

我想要这种类型的输出有什么办法吗?

name    phonecode
parth    +91
test     +444

name    country code
parth    +91
test     +444

提前致谢

您可以覆盖 getExportFields() 方法。

public function getExportFields()
{
    return array('name', 'countrycode');
}

覆盖已经提到的 getExportFields 但使用数组映射名称...关键是列标题...

public function getExportFields()
{
    $dynamicColumnCaption = ...;

    return array($dynamicColumnCaption => 'phonecode', 
                 'anotherColumnCaption' => 'columnName');
}