Response
class Response (View source)
Properties
mixed | $content | Berisi konten response. |
|
protected Response | $foundation | Berisi instanve http foundation response. |
Methods
Buat instance Response baru.
Ambil instance foundation rersponse.
Buat instance Response baru.
Buat sebuah instance response baru berupa view.
Buat sebuah instance response JSON.
Buat sebuah instance response JSONP.
Buat sebuah instance response dari Facile Model yang diubah ke JSON.
Buat instance response download.
Kirim haeder dan konten response ke browser.
Ubah konten response menjadi string.
Kirim semua headers ke browser.
Set cookie di http foundation response.
Get / set status code response.
Merender response ketika di cast ke string.
Details
__construct(mixed $content, int $status = 200, array $headers = [])
Buat instance Response baru.
Response
foundation()
Ambil instance foundation rersponse.
static Response
make(mixed $content, int $status = 200, array $headers = [])
Buat instance Response baru.
// Buat sebuah instance response dengan konten berupa string
return Response::make(json_encode($user));
// Buat sebuah instance response dengan status code kustom
return Response::make('Not Found', 404);
// Buat sebuah instance response dengan beberapa custom headers
return Response::make(json_encode($user), 200, ['header' => 'value']);
static Response
view(string $view, array $data = [], int $status = 200, array $headers = [])
Buat sebuah instance response baru berupa view.
// Buat sebuah instance response berupa sebuah view
return Response::view('home.index');
// Buat sebuah instance response berupa sebuah view dan data
return Response::view('home.index', ['name' => 'Budi']);
static Response
json(mixed $data, int $status = 200, array $headers = [], int $json_options = 0)
Buat sebuah instance response JSON.
// Buat sebuah instance response berupa JSON.
return Response::json($data, 200, ['header' => 'value']);
static Response
jsonp($callback, mixed $data, int $status = 200, array $headers = [])
Buat sebuah instance response JSONP.
// Buat sebuah instance response JSONP.
return Response::jsonp('myFunctionCall', $data, 200, ['header' => 'value']);
static Response
facile(Facile|array $data, int $status = 200, array $headers = [])
Buat sebuah instance response dari Facile Model yang diubah ke JSON.
// Buat sebuah instance response dari Facile Model yang diubah ke JSON
return Response::facile($data, 200, ['header' => 'value']);
static Response
error(int $code, array $headers = [])
Buat instance response error.
Status code dari response errornya harus menggunakan HTTP status codes. Error code yang dipilih juga harus cocok dengan nama file view di dalam folder application/views/error/. Silahkan tambahkan file view error baru jika belum ada.
// Buat response 404
return Response::error(404);
// Buat response error dengan custom header
return Response::error(429, ['Retry-After' => 1234567]);
static Response
download(string $path, string $name = null, array $headers = [])
Buat instance response download.
// Buat response download ke sebuah file
return Response::download('path/to/file.jpg');
// Buat response download ke sebuah file dengan nama kustom
return Response::download('path/to/file.jpg', 'kittens.jpg');
static Response
prepare(mixed $response)
Siapkan sebuah response dari value yang diberikan.
send()
Kirim haeder dan konten response ke browser.
string
render()
Ubah konten response menjadi string.
send_headers()
Kirim semua headers ke browser.
protected
cookies()
Set cookie di http foundation response.
Response
header(string $name, string $value)
Tambahkan header ke array response headers.
Parameter
headers()
Ambil headers dari http foundation response.
mixed
status(int $status = null)
Get / set status code response.
string
__toString()
Merender response ketika di cast ke string.