The webworksCSVBundle
helps you to handle csv data and files in your Symfony application. It provides a simple YAML based mapping for doctrine.
- PHP 7.x
- Symfony 3.x
- See also the composer.json file
Require the bundle with composer:
composer require webworksnbg/csv-bundle "~0.1"
Enable the bundle in the kernel:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new webworks\CSVBundle\webworksCSVBundle(),
// ...
);
}
Create a YAML file with the following content (for example):
# app/config/csv/mapping.yml
import:
# not supported in the current version
export:
clients: # mapping name
class: acme\AppBundle\Entity\Kunde
mapping:
name: firstname, lastname
street: street
city: zip, city
email: email
company: company_name
Note: Currently, only one export of the data is possible. The import function will follow shortly
You can call the service from container:
// where ever you have an container
$csvPath = $this->getContainer()->get('webworks.csv.mapping')
->setMappingName('clients') // mapping name
->setMode('export')
->process()
->getPath(); // Temporary file path!
Now, you can easily write data from your database via doctrine to csv.
This bundle has been created by webworks nürnberg and the community.
use webworks\CSVBundle\Lib\ParseCSV;
$parser = new ParseCSV('example.csv', ';', '"');
$data = $parser->parse();