承接 goldbach-algorithms/symfony-entity-exporter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

goldbach-algorithms/symfony-entity-exporter

Composer 安装命令:

composer require goldbach-algorithms/symfony-entity-exporter

包简介

Symfony Entity Exporter

README 文档

README

License: MIT

Goldbach Algorithms Symfony Entity Exporter (fondly nicknamed Entity Exporter) is a library developed for the Symfony framework with the objective of exporting information from the database in a simple way.

Compatible output extensions: CSV, XLS and PDF

Installation

Use the composer to install

composer require goldbach-algorithms/symfony-entity-exporter

Configuration

Make the settings below according to your project's needs within your .env file

ENTITY_PATH

If you have changed the paron directory for entities in your project, you must set the ENTITY_PATH variable within your .env file to indicate the new directory.

TRANSITORY_MEMORY

As an option it is also possible to define within the .env file of your project a value for the variable TRANSITORY_MEMORY, which will change the php memory limit during the execution of the export to avoid crashes. The default value is 1GB.

Usage

See some examples of using Symfony Entity Exporter

See the .csv export example

use GoldbachAlgorithms\SymfonyEntityExporter\SymfonyEntityExporter;

# Instantiate a new Entity Exporter
$entityExporter = new SymfonyEntityExporter;

# Set $data (query return) and entity class
$response = $entityExporter->csv(
            $data,
            User::class,
            UserDataExport::class, # Data Export Template (not required)
            'Title', # Title (not required)
            'Filename', # File .csv name (not required)
            ';' # .csv Delimiter (not required) default ;
        );

# Exporting file (.csv)
return $response;

You can also generate a .pdf file from the entity query return.

See the .pdf export example

use GoldbachAlgorithms\SymfonyEntityExporter\SymfonyEntityExporter;

# Instantiate a new Entity Exporter
$entityExporter = new SymfonyEntityExporter;

# Set $data (query return) and entity class
$response = $entityExporter->pdf(
            $data,
            User::class,
            UserDataExport::class, # Data Export Template (not required)
            'Filename', # File .pdf name (not required),
            'Header content', # (not required)
            'Footer content', # (not required)
            'P', # Portrait or Landscape (not required)
            '10', # Margin Header (not required)
            '10', # Margin Footer (not required)
            '10', # Top content margin (not required)
            'A4', # Print Format (not required)
            'utf-8', # Char Mode (not required)
        );

# Exporting file (.pdf)
return $response;

And you can also export an html template, for example a twig file

See the .pdf by html export example

use GoldbachAlgorithms\SymfonyEntityExporter\SymfonyEntityExporter;

# Instantiate a new Entity Exporter
$entityExporter = new SymfonyEntityExporter;

# Set a content
$content = $this->renderView('content.html.twig', $vars);

# Call the method pdfByHtml()
$response = $entityExporter->pdfByHtml(
            $content,
            'Filename', # File .pdf name (not required),
            'Header content', # (not required)
            'Footer content', # (not required)
            'P', # Portrait or Landscape (not required)
            '10', # Margin Header (not required)
            '10', # Margin Footer (not required)
            '10', # Top content margin (not required)
            'A4', # Print Format (not required)
            'utf-8', # Char Mode (not required)
        );

# Exporting file (.pdf)
return $response;

You can create an export template following the example in src/ExampleDataExport.php by adding a App\DataExport directory to your application.

EasyAdminBundle

The Entity Exporter is compatible with the Easy Admin Bundle, so it is possible to use a request within a Controller on the page and perform data export.

See the .xls export example

use EasyCorp\Bundle\EasyAdminBundle\Factory\AdminContextFactory;
use GoldbachAlgorithms\SymfonyEntityExporter\SymfonyEntityExporter;

# Inject the AdminContextFactory and define public

/** @var AdminContextFactory  */
public $adminContextFactory;

public function __construct(AdminContextFactory $adminContextFactory)
{
   $this->adminContextFactory = $adminContextFactory;
}

# Instantiate a new Entity Exporter
$entityExporter = new SymfonyEntityExporter;

# Get the FilterFactory into Controller
$filterFactory = $this->get(FilterFactory::class);

# Use the Entity Exporter builder to EasyAdmin
$data = $entityExporter->getEasyAdminQuery(
            $request,
            $filterFactory,
            $this,
            [
                'id' => 1
            ]
        );

# Set $data (query return) and entity class
$response = $entityExporter->xls($data, User::class);

# File .xls
return $response;

License

MIT

Copyright © 2021 Goldbach Algorithms

统计信息

  • 总下载量: 130
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固