Skip to content

xsuchy09/nette-csv-response

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSV Response

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')
;

Packages

No packages published

Languages

  • PHP 100.0%