PHP code example of ilbee / csv-response

1. Go to this page and download the library: Download ilbee/csv-response library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ilbee / csv-response example snippets



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