Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 20b01d9

Browse files
committed
Update documentation to add document new CsvResponse class
In the style of the existing Response class documentation, this change adds a section covering the new CsvResponse class.
1 parent 62b2605 commit 20b01d9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/book/v2/custom-responses.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,34 @@ $response = new Zend\Diactoros\Response\JsonResponse(
132132
);
133133
```
134134

135+
## CSV Responses
136+
137+
`Zend\Diactoros\Response\CsvResponse` creates a plain text response. It sets the
138+
`Content-Type` header to `text/csv` by default:
139+
140+
```php
141+
$csvContent = <<<EOF
142+
"first","last","email","dob",
143+
"john","citizen","[email protected]","01/01/1970",
144+
EOF;
145+
146+
$response = new Zend\Diactoros\Response\CsvResponse($csvContent);
147+
```
148+
149+
The constructor accepts three additional arguments:
150+
151+
- A status code
152+
- A filename, if the response is to be sent as a download
153+
- An array of supplemental headers
154+
155+
```php
156+
$response = new Zend\Diactoros\Response\TextResponse(
157+
$text,
158+
200,
159+
'monthly-sports-report.csv',
160+
['X-Generated-By' => ['zend-diactoros']]
161+
);
162+
135163
## Empty Responses
136164

137165
Many API actions allow returning empty responses:

0 commit comments

Comments
 (0)