Skip to content

ilbee/csv-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSVResponse

Active repository License PHP Composer

Add a CSV export response in your [Symfony] controller.

📖 Table of Contents

  1. ℹ️ Prerequisites
  2. ⚙ Installation
  3. 🛠️ How to Use
  4. 🔗 Useful Links
  5. 🙏 Thanks

ℹ️ 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

  1. CSVResponse: This class generates an HTTP response that will trigger a CSV file download based on the provided data.
  2. Data Example: You can replace the $data array with your own data, fetched from a database or other sources.

🔗 Useful Links

  • Symfony - Official Symfony Documentation
  • Composer - PHP Dependency Manager

🙏 Thanks

Special thanks to Paul Mitchum and Dan Feder for their contributions!

About

CSV Response for Symfony 4.4 project

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •  

Languages