webworksnbg / csv-bundle
webworksCSVBundle
Installs: 82
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Type:symfony-bundle
Requires
- php: ^5.5.9|>=7.0.8
- doctrine/doctrine-bundle: ^1.6
- doctrine/orm: ^2.5
Suggests
- psr/log: Allows logging
This package is not auto-updated.
Last update: 2023-02-12 01:39:49 UTC
README
The webworksCSVBundle
helps you to handle csv data and files in your Symfony application. It provides a simple YAML based mapping for doctrine.
Requirements
- PHP 7.x
- Symfony 3.x
- See also the composer.json file
Installation
Step 1: Download webworksCSVBundle using composer
Require the bundle with composer:
composer require webworksnbg/csv-bundle "~0.1"
Step 2: Enable the bundle
Enable the bundle in the kernel:
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new webworks\CSVBundle\webworksCSVBundle(), // ... ); }
Step 3: Create the mapping YAML file
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
Step 4: Use the mapping service to write data from your database to csv
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!
Step 5: Enjoy :)
Now, you can easily write data from your database via doctrine to csv.
Credits
This bundle has been created by webworks nürnberg and the community.
Examples
Parse CSV file
use webworks\CSVBundle\Lib\ParseCSV; $parser = new ParseCSV('example.csv', ';', '"'); $data = $parser->parse();