ilbee / csv-response
Symfony component allow you to respond CSV contents directly in your controller
Installs: 104โ070
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 2
Open Issues: 0
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: 2025-03-10 09:51:31 UTC
README
Add a CSV export response in your [Symfony] controller.
๐ Table of Contents
โน๏ธ Prerequisites
- PHP >= 7.4
- Symfony >= 4.4
โ Installation
Use [Composer] to install this package:
composer require ilbee/csv-response
๐ ๏ธ How to use ?
Simply return a CSVResponse object in your Symfony controller, and you will be able to download a CSV file.
Hereโs 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); } }
Explanation
- CSVResponse: This class generates an HTTP response that will trigger a CSV file download based on the provided data.
- Data Example: You can replace the
$data
array with your own data, fetched from a database or other sources.
๐ Useful Links
๐ Thanks
Special thanks to Paul Mitchum and Dan Feder for their contributions!