symfony2 - How to make instant redirection in Laravel -
i want create instant redirection in controller in laravel.
i know can use
public function show($page) { homecoming redirect::url('http://example.com'); }
but want repeat code in many controllers adding status illustration this:
public function show($page) { $totalpages = 100; // here calculating maximum page if ($page < 2 || $page > $totalpages) { homecoming redirect::url('http://example.com'); } // rest of code here - should run if status false }
but don't want repeat code in each controller.
if seek set redirection code in other method (that exist in base of operations controller) won't work because doesn't homecoming in main controller:
public function show($page) { $totalpages = 100; // here calculating maximum page $this->checkpages($page, $totalpages, 'http://example.com'); // rest of code here - should run if status false } public function checkpages($page, $totalpages, $url) { if ($page < 2 || $page > $totalpages) { homecoming redirect::url($url); } }
how can solve issue?
after while of digging seems purposes should utilize send()
method symfony\component\httpfoundation
(laravel redirectresponse
inherits class).
so can modify checkpages
method way:
public function checkpages($page, $totalpages, $url) { if ($page < 2 or $page > $totalpages) { redirect::url($url)->send(); } }
and create instant redirection.
symfony2 redirect laravel laravel-4
No comments:
Post a Comment