php - Redirection if no parameters in the URL in Lumen -
i use lumen framework time , find myself confronted recurrent problem.
in example, page /index/validation/ requires parameter, here represented {key}. however, call /index/validation/ without parameter, don't see how don't have page not found exception.
so, created function redirect home page
routes.php
$app->get('/index/validation', 'app\http\controllers\indexcontroller@redirectindex'); $app->get('/index/validation/{key}', 'app\http\controllers\indexcontroller@validation'); indexcontroller
public function redirectindex() { return redirect('index'); } what doing here works fine, however, not sure whether apply right method, or maybe there way achieve goal ?
all uncaught exceptions handled within app\exceptions\handler. redirect on not found exceptions change render() method this:
public function render($request, exception $e) { if($e instanceof notfoundhttpexception){ return redirect('index'); } return parent::render($request, $e); } you have import class with:
use symfony\component\httpkernel\exception\notfoundhttpexception;
Comments
Post a Comment