Skip to content

ilbee/csv-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSVResponse

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