xsuchy09/nette-csv-response

Nette CSV Response

0.4 2020-11-27 12:21 UTC

This package is auto-updated.

Last update: 2024-11-27 22:06:37 UTC


README

Install:

composer require xsuchy09/nette-csv-response

Use:

class SomePresenter extends BasePresenter
{
	public function actionDefault()
	{
		$data = [
			[ 'name' => 'George', 'age' => 15, 'grade' => 2, ],
			[ 'name' => 'Jack', 'age' => 17, 'grade' => 4, ],
			[ 'name' => 'Mary', 'age' => 17, 'grade' => 1, ],
		];

		$response = new \XSuchy09\Application\Responses\CsvResponse($data, 'students.csv');
		$this->sendResponse( $response );
	}
}

Individual settings example:

use \XSuchy09\Application\Responses\CsvResponse;

// $response is instance of \XSuchy09\Application\Responses\CsvResponse
$response
	->setDelimiter(CsvResponse::SEMICOLON)
	->setEnclosure('"') // this is default value so not require to call when set to "
	->setEscapeChar('\\') // this is default value so not require to call when set to \
	->setOutputCharset('utf-8') // this is default value so not require to call when set to utf-8
	->setContentType('application/csv')
	->setHeadingFormatter('mb_strtoupper')
	->setDataFormatter('trim')
;