Created
March 27, 2014 14:00
-
-
Save gravitano/9808228 to your computer and use it in GitHub Desktop.
Simple trick for your BaseController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BaseController extends Controller { | |
/** | |
* Setup the layout used by the controller. | |
* | |
* @return void | |
*/ | |
protected function setupLayout() | |
{ | |
if ( ! is_null($this->layout)) | |
{ | |
$this->layout = View::make($this->layout); | |
} | |
} | |
/** | |
* Get the evaluated view contents for the given view. | |
* | |
* @param string $view | |
* @param array $data | |
* @param array $mergeData | |
* @return \Illuminate\View\View | |
*/ | |
public function view($name, $data = array(), $mergeData = array()) | |
{ | |
return View::make($name, $data, $mergeData); | |
} | |
/** | |
* Create a new redirect response to the given path. | |
* | |
* @param string $path | |
* @param int $status | |
* @param array $headers | |
* @param bool $secure | |
* @return \Illuminate\Http\RedirectResponse | |
*/ | |
public function redirect($path, $status = 302, $headers = array(), $secure = null) | |
{ | |
return Redirect::to($path, $status, $headers, $secure); | |
} | |
/** | |
* Create a new redirect response to a named route. | |
* | |
* @param string $route | |
* @param array $parameters | |
* @param int $status | |
* @param array $headers | |
* @return \Illuminate\Http\RedirectResponse | |
*/ | |
public function redirectRoute($route, $parameters = array(), $status = 302, $headers = array()) | |
{ | |
return Redirect::route($route, $parameters, $status, $headers); | |
} | |
/** | |
* Create a new redirect response to the previous location. | |
* | |
* @param int $status | |
* @param array $headers | |
* @return \Illuminate\Http\RedirectResponse | |
*/ | |
public function redirectBack($status = 302, $headers = array()) | |
{ | |
return Redirect::back($status, $headers); | |
} | |
/** | |
* Create a new redirect response to the "home" route. | |
* | |
* @param int $status | |
* @return \Illuminate\Http\RedirectResponse | |
*/ | |
public function redirectHome($status = 302) | |
{ | |
return Redirect::home($status); | |
} | |
/** | |
* Create a new redirect response to the previous location. | |
* | |
* @param int $status | |
* @param array $headers | |
* @return \Illuminate\Http\RedirectResponse | |
*/ | |
public function goBack($status = 302, $headers = array()) | |
{ | |
return $this->redirectBack($status, $headers); | |
} | |
/** | |
* Create a new redirect response to the "home" route. | |
* | |
* @param int $status | |
* @return \Illuminate\Http\RedirectResponse | |
*/ | |
public function goHome($status) | |
{ | |
return $this->redirectHome($status); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Contoh Penggunaan :
Alternatif kode untuk menampilkan view :
Alternatif kode untuk meredirect ke halaman (uri) tertentu :
Untuk method lainnya, cara pemanggilannya sama seperti memanggil method dari class tertentu pada umumnya.
Tinggal diatur sesuai kebutuhan saja :)