class Redirect extends Response (View source)

Properties

mixed $content

Berisi konten response.

from  Response
protected Response $foundation

Berisi instanve http foundation response.

from  Response

Methods

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

Buat instance Response baru.

from  Response
foundation()

Ambil instance foundation rersponse.

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

Buat instance Response baru.

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

Buat sebuah instance response baru berupa view.

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

Buat sebuah instance response JSON.

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

Buat sebuah instance response JSONP.

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

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

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

Buat instance response error.

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

Buat instance response download.

from  Response
static Response
prepare(mixed $response)

Siapkan sebuah response dari value yang diberikan.

from  Response
send()

Kirim header dan konten respon ke browser.

string
render()

Ubah konten response menjadi string.

from  Response
send_headers()

Kirim semua headers ke browser.

from  Response
cookies()

Set cookie di http foundation response.

from  Response
header(string $name, string $value)

Tambahkan header ke array response headers.

from  Response
headers()

Ambil headers dari http foundation response.

from  Response
mixed
status(int $status = null)

Get / set status code response.

from  Response
string
__toString()

Merender response ketika di cast ke string.

from  Response
static Redirect|mixed
home(int $status = 302)

Buat respon redirect ke root aplikasi.

static Redirect|mixed
back(int $status = 302)

Buat respon redirect ke halaman sebelumnya.

static Redirect|mixed
to(string $url, int $status = 302)

Buat respon redirect.

static Redirect|mixed
to_action(string $action, array $parameters = [], int $status = 302)

Buat respon redirect sebuah action milik controller.

static Redirect|mixed
to_route(string $route, array $parameters = [], int $status = 302)

Buat respon redirect ke named route.

Redirect|mixed
with(string $key, mixed $value)

Tambahkan sebuah item ke flash data (disimpan ke session).

Redirect|mixed
with_input(string $filter = null, array $items = [])

Flash data inputan lama ke session dan return instance Redirect.

Redirect|mixed
with_errors(Validator|Messages $container)

Flash pesan error dari kelas Validator ke session.

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 header dan konten respon 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

static Redirect|mixed home(int $status = 302)

Buat respon redirect ke root aplikasi.

Parameters

int $status

Return Value

Redirect|mixed

static Redirect|mixed back(int $status = 302)

Buat respon redirect ke halaman sebelumnya.

Parameters

int $status

Return Value

Redirect|mixed

static Redirect|mixed to(string $url, int $status = 302)

Buat respon redirect.


     // Buat redirect ke lokasi tertentu dalam lingkup aplikasi
     return Redirect::to('user/profile');

     // Buat redirect dengan status code 301
     return Redirect::to('user/profile', 301);

Parameters

string $url
int $status

Return Value

Redirect|mixed

static Redirect|mixed to_action(string $action, array $parameters = [], int $status = 302)

Buat respon redirect sebuah action milik controller.

Parameters

string $action
array $parameters
int $status

Return Value

Redirect|mixed

static Redirect|mixed to_route(string $route, array $parameters = [], int $status = 302)

Buat respon redirect ke named route.


     // Buat respon redirect ke named route bernama 'login'
     return Redirect::to_route('login');

     // Buat respon redirect ke named route bernama 'profile' dengan parameter tambahan
     return Redirect::to_route('profile', [$name]);

Parameters

string $route
array $parameters
int $status

Return Value

Redirect|mixed

Redirect|mixed with(string $key, mixed $value)

Tambahkan sebuah item ke flash data (disimpan ke session).

Flash data akan tetap tersedia pada request selanjutnya.


     // Buat respon redirect dengan flash data.
     return Redirect::to('profile')->with('message', 'Selamat datang kembali!');

Parameters

string $key
mixed $value

Return Value

Redirect|mixed

Redirect|mixed with_input(string $filter = null, array $items = [])

Flash data inputan lama ke session dan return instance Redirect.

Setelah inputan lama di-flash, Anda bisa mengambilnya dengan Input::old().


     // Redirect dan flash semua data inputan ke session.
     return Redirect::to('login')->with_input();

     // Redirect dan flash hanya beberapa data inputan ke session.
     return Redirect::to('login')->with_input('only', ['email', 'name']);

     // Redirect dan flash semua data kecuali data-data yang disebutkan
     return Redirect::to('login')->with_input('except', ['password', 'api_token']);

Parameters

string $filter
array $items

Return Value

Redirect|mixed

Redirect|mixed with_errors(Validator|Messages $container)

Flash pesan error dari kelas Validator ke session.

Method ini memudahkan Anda ketika ingin mengoper pesan error validasi ke view.


     // Redirect dan flash pesan error validator ke session
     return Redirect::to('register')->with_errors($validator);

Parameters

Validator|Messages $container

Return Value

Redirect|mixed