tangoman / csv-export-helper
Symfony CSV Export Helper
This package's canonical repository appears to be gone and the package has been frozen as a result.
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2020-10-16 14:57:29 UTC
README
TangoMan CSV Export Helper provides automatic csv export function.
How to install
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require tangoman/csv-export-helper
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
How to use
Inside your controller: Add "use" statement just like when you're using a trait.
<?php namespace AppBundle\Controller; use AppBundle\Entity\Foobar; use TangoMan\CSVExportHelper\CSVExportHelper; /** * Class Foobar * * @package AppBundle\Controller */ class FoobarController extends Controller { use CSVExportHelper; // ... /** * Exports foobar list in csv format. * @Route("/export") */ public function exportAction() { $em = $this->get('doctrine')->getManager(); $foobars = $em->getRepository('AppBundle:Foobar')->export(); $response = $this->exportCSV($foobars); return new Response( $response, 200, [ 'Content-Type' => 'application/force-download', 'Content-Disposition' => 'attachment; filename="foobars.csv"', ] ); }
Your repository need to return result as array:
<?php namespace AppBundle\Repository; use Doctrine\ORM\EntityRepository; /** * Class FoobarRepository * * @package AppBundle\Repository */ class FoobarRepository extends EntityRepository { /** * Return all objects as scalar result (no pagination) * * @return array */ public function export() { $dql = $this->createQueryBuilder('foobar'); return $dql->getQuery()->getScalarResult(); }
Note
If you find any bug please report here : Issues
License
Copyright (c) 2018 Matthias Morin
Distributed under the MIT license.
If you like TangoMan Entity Helper please star! And follow me on GitHub: TangoMan75 ... And check my other cool projects.