Giter VIP home page Giter VIP logo

rdn-csv's Introduction

RdnCsv

The RdnCsv ZF2 module makes it really easy to export and import CSV files.

How to install

  1. Use composer to require the radnan/rdn-csv package:

    $ composer require radnan/rdn-csv:1.*
  2. 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.

Read more documentation on csvImport()

rdn-csv's People

Contributors

radnan avatar fabaopaiva avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.