LoginSignup
2
2

More than 5 years have passed since last update.

cakephp3 csv出力

Posted at

cakephp3 でcsv出力をします。
プラグインを使用して簡単に作成します。

公式
https://qiita.com/shigejun/items/0c2a8110422ffd0e119d

インストールする

composer require friendsofcake/cakephp-csvview:~3.0

プログラム修正

config/bootstrap.php
Plugin::load('CsvView');

使用する

単純に$data配列をcsv出力する例です。
ヘッダーを付けたりフッターを付けたりなどもできるので、
それは公式を参考にしてください。

public function export()
{
    $data = [
        ['a', 'b', 'c'],
        [1, 2, 3],
        ['you', 'and', 'me'],
    ];
    $_serialize = 'data';

    $this->viewBuilder()->className('CsvView.Csv');
    $this->set(compact('data', '_serialize'));
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2