dev-master
9999999-dev https://github.com/chrisoconnell/CaoCsvOutputZend Framework 2 Module for generating CSV output from an array.
The Requires
- php >=5.3.3
- zendframework/zendframework 2.*
csv zf2 module zendframework
Zend Framework 2 Module for generating CSV output from an array.
Zend Framework 2 Module for generating CSV output from an array., (*1)
This module provides both a Model and View Helper with which you can use to output
the csv data. When using the view helper, the output will automatically be passed
throught the escapeHtml view helper and all new lines will be converted to <br>
., (*2)
./vendor/
../vendor/
directory.Add this project in your composer.json:, (*3)
"require": { "chrisoconnell/cao-csv-output": "dev-master" }
Now tell composer to download CaoCsvOutput by running the command:, (*4)
$ php composer.phar update
Enabling it in your application.config.php
file., (*5)
<?php return array( 'modules' => array( // ... 'CaoCsvOutput', ), // ... );
You can either create an instance of CaoCsvOutput\Model\Csv
or use the view helper
csvOutput
., (*6)
CaoCsvOutput\Model\Csv
using $data
as the input.Output the result using the render
method., (*7)
$data = array( array('a', 1, 'a + b'), array('b', '"', ';'), ); $csv = new CaoCsvOutput\Model\Csv($data); $output = $csv->render();
Which will set $output
to be, (*8)
a;1;"a + b" b;"""";";"
From within your view script (.phtml file) simply call the view helper., (*9)
echo $this->csvOutput($data);
You can easily change the characters used for the CSV output by setting the attributes parameters when calling either the View Helper or the Model class., (*10)
;
"
false
.
By default, only fields which contain a space, the delimiter, or the enclosure will be enclosed by
the enclosure character.echo $this->csvOutput($data, ',', "'", true);
If using the input from above, the output would be, (*11)
'a','1','a + b' 'b','"',';'
Zend Framework 2 Module for generating CSV output from an array.
csv zf2 module zendframework