Redirect
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
Buat instance Response baru.
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.
Siapkan sebuah response dari value yang diberikan.
Kirim header dan konten respon ke browser.
Buat respon redirect sebuah action milik controller.
Buat respon redirect ke named route.
Tambahkan sebuah item ke flash data (disimpan ke session).
Flash data inputan lama ke session dan return instance Redirect.
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 header dan konten respon 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.
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.
// 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);
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.
// 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]);
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!');
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']);
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);