Response
in package
Weaver Framework - Response Class
This class provides common functionality for handling responses, including JSON and CSV output.
Table of Contents
Methods
Methods
csv()
Generate and download a CSV file.
public
csv(array<string|int, mixed> $data[, string $filename = null ]) : void
This method takes an array of data and converts it into a CSV file that the user can download.
Parameters
- $data : array<string|int, mixed>
-
The data to be converted to CSV format. Data format: [ ["Name", "Age", "Email"], ["John Doe", 30, "john@example.com"], ["Jane Smith", 25, "jane@example.com"], ]
- $filename : string = null
-
(Optional) The name of the downloaded CSV file (e.g., "example.csv"). If not provided, the default filename will be the current date in "YYYY-MM-DD.csv" format.
json()
Send a JSON response.
public
static json(array<string|int, mixed> $data) : void
This method sends a JSON response with the provided data and sets the appropriate headers.
Parameters
- $data : array<string|int, mixed>
-
The data to be encoded as JSON.