Add a CSV export Response in your Symfony controller.
Use Composer to install this package :
composer require ilbee/csv-response
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);
}
}