ilbee / csv-response
Symfony component allow you to respond CSV contents directly in your controller
Installs: 87 612
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 1
Requires
- php: >=7.4 <9
- symfony/http-foundation: ^4 || ^5 || ^6 || ^7
Requires (Dev)
- phpunit/phpunit: ^9.6
- rector/rector: ^0.15.21
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-11-05 14:35:57 UTC
README
Add a CSV export Response in your Symfony controller.
Installation
Use Composer to install this package :
composer require ilbee/csv-response
How to use ?
Just return a CSVResponse object in your Symfony Controller and you will be able to download a CSV file.
Here is a simple example :
<?php // ./src/Controller/MyController.php namespace App\Controller; use Ilbee\CSVResponse\CSVResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; class MyController extends AbstractController { /** * @Route("/download-csv", name="download_csv") */ public function downloadCsv(): CSVResponse { $data = []; $data[] = [ 'firstName' => 'Marcel', 'lastName' => 'TOTO', ]; $data[] = [ 'firstName' => 'Maurice', 'lastName' => 'TATA', ]; return new CSVResponse($data); } }