This package is a PHP object-oriented solution for modelling data in two (rows + columns) or three dimensions (rows + columns + pages). It can be thought of like a spreadsheet.
It allows a single data class ExportData
to be used to organize your data in a grid, with various output styles Exporter
so you can easily get a .csv
file or a .xlsx
file, among many others.
See the code for more documentation.
- >= Php 5.3.0
- Please install necessary dependencies using Composer.
- Navigate to the root of this package and type:
composer install
- Refer to the Doxygene documentation included in this package.
- Download a copy of simpletest to the
tests
directory - Visit
tests/all_tests.php
in your browser to run all tests at once; or visit a single test file instead. - If you're getting forbidden errors, take a look at the
.htaccess
file.
In this example we'll build a 2 paged model, the first page contains two columns (names and ages) of three people. The second page will contain two rows of vehicle information (color and make).
$obj = new ExportData();
// By default we're on page 0, row 0.
$obj->add('Name', 'Aaron')->add('Age', 39)->next();
$obj->add('Name', 'Hillary')->add('Age', 37)->next();
$obj->add('Name', 'Maia')->add('Age', 7)->next();
// Switch to page 1; we'll be placed on row 0 when the new page is created.
$obj->setPage(1);
$obj->add('Color', 'Black')->add('Make', 'Subaru')->next();
$obj->add('Color', 'White')->add('Make', 'Hyundai')->next();
$obj->setPage(0)->setPointer(0)->getValue('Name') === 'Aaron'
$obj->getValue('Name') === 'Aaron'
$obj->setPointer(2)->getValue('Name') === 'Maia'
$obj->setPointer(0)->get() === array('Name' => 'Aaron', 'Age' => 39)
$obj->setPage(1)->setPointer(1)->getValue('Color') === 'White'
And now to get that as a CSV file we do...
$exporter = new CSVExporter($obj);
$csv_string = $exporter->export();
Or to get it as JSON...
$exporter = new JSONExporter($obj);
$json_string = $exporter->export();
Or any of the other exporter classes.
use AKlump\LoftDataGrids\XLSXExporter;
$exporter = new XLSXExporter($obj, 'users');
$exporter->saveFile();
- In the Loft Studios
- Aaron Klump - Developer
- PO Box 29294 Bellingham, WA 98228-1294
- aim: theloft101
- skype: intheloftstudios
- d.o: aklump
- http://www.InTheLoftStudios.com