ilbee/csv-response

Symfony component allow you to respond CSV contents directly in your controller

1.2.0 2024-02-05 11:39 UTC

This package is auto-updated.

Last update: 2024-04-05 13:24:54 UTC


README

Active repository License SymfonyInsight Php Composer

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);
    }
}