PHPackages                             dario86/cakephp-csv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dario86/cakephp-csv

ActiveCakephp-plugin[Utility &amp; Helpers](/categories/utility)

dario86/cakephp-csv
===================

0561PHP

Since May 5Pushed 10y ago1 watchersCompare

[ Source](https://github.com/dario86/CakePHP-CSV)[ Packagist](https://packagist.org/packages/dario86/cakephp-csv)[ RSS](/packages/dario86-cakephp-csv/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (3)Used By (0)

CSV Plugin
==========

[](#csv-plugin)

Allows the importing and exporting of a standard $this-&gt;data formatted array to and from csv files. Doesn't currently support HABTM.

Options
-------

[](#options)

Importing, exporting and setup come with the same options and default values

```
$options = array(
	// Refer to php.net fgetcsv for more information
	'length' => 0,
	'delimiter' => ',',
	'enclosure' => '"',
	'escape' => '\\',
	// Generates a Model.field headings row from the csv file
	'headers' => true,
	// If true, String $content is the data, not a path to the file
	'text' => false,
        'array' => false
)
```

Instructions
------------

[](#instructions)

- Add Behavior to the table

```

```

### Importing

[](#importing)

- Upload a csv file to the server
- Import the csv file into your data variable:

**Approach 1:** Use a CSV file with the first row being Model.field headers

```
Posts.csv
Post.title, Post.created, Post.modified, body, user_id, Section.name, Category.0.name, Category.0.description, Category.1.name, Category.1.description
..., ..., ...
```

```
$this->data = $this->Posts->import($content, $options);
```

**Approach 2:** Pass an array of fields (in order) to the method

```
$data = $this->Posts->import($content, array('Post.title', 'Post.created', 'Post.modified', 'body', 'user_id', 'Category.0.name', 'Category.0.description', 'Category.1.name', 'Category.1.description'));
```

- Process/save/whatever with the data

```
$entities = $this->Posts->newEntities($data);
$Table = $this->Posts;
$Table->connection()->transactional(function () use ($Table, $entities) {
    foreach ($entities as $entity) {
        $Table->save($entity, ['atomic' => false]);
    }
});
```

### Exporting

[](#exporting)

**Approach 1:** Entity

- Populate a $this-&gt;data type entity

```
$data = $this->Post->find()->all();
```

- Export to a file in a writeable directory

```
$this->Posts->exportCsv($filepath, $data, $options);
```

**Approach 2:** Array

- Populate an $this-&gt;data type array

```
$data = $this->Post->find()->toArray();
```

- Export to a file in a writeable directory. In config, set option `array` to true

```
$options['array'] = true;
$this->Posts->exportCsv($filepath, $data, $options);
```

### Additional optional callbacks:

[](#additional-optional-callbacks)

- `beforeImportCsv($filename, $fields, $options)` returns boolean $continue
- `afterImportCsv($data)`
- `beforeExportCsv($filename, $data, $options)` returns boolean $continue
- `afterExportCsv()`

### FAQ

[](#faq)

#### Incorrect Line Endings (OSX)

[](#incorrect-line-endings-osx)

Some people [have mentioned](https://github.com/ProLoser/CakePHP-CSV/issues/6) having incorrect line endings. This can be fixed by having this in your php codebase:

```
ini_set("auto_detect_line_endings", true);

```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 54.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ca03119ea82f84d899f3303fb6ecb8535425f79eabf2db61e970346dcaac0dc?d=identicon)[dario86](/maintainers/dario86)

---

Top Contributors

[![ProLoser](https://avatars.githubusercontent.com/u/67395?v=4)](https://github.com/ProLoser "ProLoser (19 commits)")[![rochamarcelo](https://avatars.githubusercontent.com/u/850748?v=4)](https://github.com/rochamarcelo "rochamarcelo (9 commits)")[![paulleephp](https://avatars.githubusercontent.com/u/2199146?v=4)](https://github.com/paulleephp "paulleephp (2 commits)")[![ravage84](https://avatars.githubusercontent.com/u/625761?v=4)](https://github.com/ravage84 "ravage84 (1 commits)")[![emacaste](https://avatars.githubusercontent.com/u/4621873?v=4)](https://github.com/emacaste "emacaste (1 commits)")[![webnard](https://avatars.githubusercontent.com/u/1213808?v=4)](https://github.com/webnard "webnard (1 commits)")[![JacopKane](https://avatars.githubusercontent.com/u/68406?v=4)](https://github.com/JacopKane "JacopKane (1 commits)")[![krecik](https://avatars.githubusercontent.com/u/324543?v=4)](https://github.com/krecik "krecik (1 commits)")

### Embed Badge

![Health badge](/badges/dario86-cakephp-csv/health.svg)

```
[![Health](https://phpackages.com/badges/dario86-cakephp-csv/health.svg)](https://phpackages.com/packages/dario86-cakephp-csv)
```

###  Alternatives

[lizhichao/one-sm

国密sm3

1881.5M7](/packages/lizhichao-one-sm)[aymanalhattami/filament-context-menu

context menu (right click menu) for filament

10039.0k](/packages/aymanalhattami-filament-context-menu)[tivie/command

An utility library that harmonizes OS differences and executes external programs in a safer way

1257.9k1](/packages/tivie-command)[kern046/changelog-parser

PHP library used to parse a CHANGELOG.md file and return JSON output

106.4k1](/packages/kern046-changelog-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
