2017 © Pedro Peláez
 

library cao-csv-output

Zend Framework 2 Module for generating CSV output from an array.

image

chrisoconnell/cao-csv-output

Zend Framework 2 Module for generating CSV output from an array.

  • Tuesday, September 3, 2013
  • by chrisoconnell
  • Repository
  • 2 Watchers
  • 5 Stars
  • 9,375 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 1 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

CaoCsvOutput

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)

Installation

Main Setup

By cloning project

  1. Install the CaoCsvOutput ZF2 module by cloning it into ./vendor/.
  2. Clone this project into your ./vendor/ directory.

With composer

  1. Add this project in your composer.json:, (*3)

    "require": {
        "chrisoconnell/cao-csv-output": "dev-master"
    }
    
  2. Now tell composer to download CaoCsvOutput by running the command:, (*4)

    $ php composer.phar update
    

Post installation

  1. Enabling it in your application.config.php file., (*5)

    <?php
    return array(
        'modules' => array(
            // ...
            'CaoCsvOutput',
        ),
        // ...
    );
    

Usage

You can either create an instance of CaoCsvOutput\Model\Csv or use the view helper csvOutput., (*6)

Example of Instance

  1. Define the data as an array.
  2. Create a new instance of CaoCsvOutput\Model\Csv using $data as the input.
  3. 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();
    
  4. Which will set $output to be, (*8)

    a;1;"a + b"
    b;"""";";"
    

View Helper Example

  1. Define the data like before.
  2. From within your view script (.phtml file) simply call the view helper., (*9)

    echo $this->csvOutput($data);
    

Input Parameters

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)

Data
(array) Input array which gets converted to CSV output
Delimiter
(string) Character separating the fields of the CSV output. Default is ;
Enclosure
(string) Character that surounds the field text. Default is "
Enclose All
(bool) If every field should be enclosed by the Enclosure string or not.
Defalut is false. By default, only fields which contain a space, the delimiter, or the enclosure will be enclosed by the enclosure character.

Example

echo $this->csvOutput($data, ',', "'", true);

If using the input from above, the output would be, (*11)

'a','1','a + b'
'b','"',';'

The Versions

03/09 2013

dev-master

9999999-dev https://github.com/chrisoconnell/CaoCsvOutput

Zend Framework 2 Module for generating CSV output from an array.

  Sources   Download

The Requires

 

csv zf2 module zendframework