繁体   English   中英

如何在 SonataAdminBundle 中自定义导出

[英]How to custom export in SonataAdminBundle

我正在尝试找到一种在我的实体管理员上自定义导出 csv 的方法。

理想情况下,我需要从实体的函数中提取数据以将其放入 csv 文件中。

我列出了要使用 configureExportFields() 函数提取的字段,并且我尝试使用 getDataSourceIterator() 方法修改请求,但似乎导出出错。

如果有人知道如何使用默认奏鸣曲导出来做到这一点

我的奏鸣曲版本:

sonata-project/admin-bundle              4.x-dev 9eb2c5f The missing Symfony Admin Generator
sonata-project/block-bundle              4.6.0           Symfony SonataBlockBundle
sonata-project/cache                     2.1.1           Cache library
sonata-project/doctrine-extensions       1.13.0          Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 4.x-dev 7dfe372 Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.7.0           Lightweight Exporter library
sonata-project/form-extensions           1.9.0           Symfony form extensions
sonata-project/twig-extensions           1.6.0           Sonata twig extensions

在 PHP 8.0.7 上

好的,我找到了这个解决方案, Sonata admin export fields with collection fields

您必须拥有一个属性而不仅仅是函数,并在函数返回中设置该属性。

这个对我有用

protected function configureExportFields(): array
{
    return [
        
        'Preferred area' => 'user.preferredNavigationAreaAddress',
        
    ];
}

在我的实体中:

protected string $preferredNavigationAreaAddress;

public function getPreferredNavigationAreaAddress(): string
{
    $preferredArea = $this->getNavigationAreas()->filter(
        function ($navigationArea) {
            return true === $navigationArea->isPreferred();
        }
    )->first();

    return $this->preferredNavigationAreaAddress = $preferredArea->getFullAddress();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM