class Response (View source)

Properties

mixed $content

Berisi konten response.

protected Response $foundation

Berisi instanve http foundation response.

Methods

__construct(mixed $content, int $status = 200, array $headers = [])

Buat instance Response baru.

foundation()

Ambil instance foundation rersponse.

static Response
make(mixed $content, int $status = 200, array $headers = [])

Buat instance Response baru.

static Response
view(string $view, array $data = [], int $status = 200, array $headers = [])

Buat sebuah instance response baru berupa view.

static Response
json(mixed $data, int $status = 200, array $headers = [], int $json_options = 0)

Buat sebuah instance response JSON.

static Response
jsonp($callback, mixed $data, int $status = 200, array $headers = [])

Buat sebuah instance response JSONP.

static Response
facile(Facile|array $data, int $status = 200, array $headers = [])

Buat sebuah instance response dari Facile Model yang diubah ke JSON.

static Response
error(int $code, array $headers = [])

Buat instance response error.

static Response
download(string $path, string $name = null, array $headers = [])

Buat instance response download.

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.

cookies()

Set cookie di http foundation response.

header(string $name, string $value)

Tambahkan header ke array response headers.

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.

Details

__construct(mixed $content, int $status = 200, array $headers = [])

Buat instance Response baru.

Parameters

mixed $content
int $status
array $headers

Response foundation()

Ambil instance foundation rersponse.

Return Value

Response

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

Parameters

mixed $content
int $status
array $headers

Return Value

Response

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

Parameters

string $view
array $data
int $status
array $headers

Return Value

Response

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

Parameters

mixed $data
int $status
array $headers
int $json_options

Return Value

Response

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

Parameters

$callback
mixed $data
int $status
array $headers

Return Value

Response

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

Parameters

Facile|array $data
int $status
array $headers

Return Value

Response

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

Parameters

int $code
array $headers

Return Value

Response

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

Parameters

string $path
string $name
array $headers

Return Value

Response

static Response prepare(mixed $response)

Siapkan sebuah response dari value yang diberikan.

Parameters

mixed $response

Return Value

Response

send()

Kirim haeder dan konten response ke browser.

string render()

Ubah konten response menjadi string.

Return Value

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.

Parameters

string $name
string $value

Return Value

Response

Parameter headers()

Ambil headers dari http foundation response.

Return Value

Parameter

mixed status(int $status = null)

Get / set status code response.

Parameters

int $status

Return Value

mixed

string __toString()

Merender response ketika di cast ke string.

Return Value

string