radnan / rdn-csv
Laminas module to export and import CSV files
Installs: 108 260
Dependents: 0
Suggesters: 0
Security: 0
Stars: 19
Watchers: 4
Forks: 19
Open Issues: 4
Requires
- laminas/laminas-http: ^2.6
- laminas/laminas-mvc: ^2.7.9 || ^3.1
Requires (Dev)
- mikey179/vfsstream: *
- phpunit/phpunit: ^5.7 || ^6.5 || ^7.5
This package is not auto-updated.
Last update: 2025-02-13 19:39:01 UTC
README
The RdnCsv Laminas module makes it really easy to export and import CSV files.
How to install
-
Use
composer
to require theradnan/rdn-csv
package:$ composer require radnan/rdn-csv:3.*
-
Activate the module by including it in your
application.config.php
file:<?php return array( 'modules' => array( 'RdnCsv', // ... ), );
How to use
The module comes with two plugins - CsvExport()
and CsvImport()
.
CsvExport()
Export data into a downloadable CSV file using this plugin.
// inside a controller action $header = array( 'Year', 'Make', 'Model', 'Description', 'Price', ); $records = array( array( '1997', 'Ford', 'E350', 'ac, abs, moon', '3000.00', ), ); return $this->CsvExport('foo.csv', $header, $records);
The plugin will return a response object which you can then return from your controller action.
Read more documentation on CsvExport()
CsvImport()
Import data from a CSV file using this plugin.
// inside a controller action $csv = $this->CsvImport('/path/to/foo.csv'); foreach ($csv as $row) { var_dump($row); // array( // 'Year' => '1997', // 'Make' => 'Ford', // 'Model' => 'E350', // 'Description' => 'ac, abs, moon', // 'Price' => '3000.00', // ) }
The plugin returns an iterator that can be used to loop over all the rows in the CSV file.