slimcontroller
slimcontroller copied to clipboard
Adding route with authentication middleware?
I really enjoy using slimcontroller. Is it possible to include an authentication middleware while defining routes in index.php ?
e.g. I have $authenticate defined:
$authenticate = function ($app) { return function () use ($app) { if (!isset($_SESSION['user'])) { $_SESSION['urlRedirect'] = $app->request()->getPathInfo(); $app->flash('error', 'Login required'); $app->redirect('/login'); } }; };
When adding routes:
$app->addRoutes(array( '/' => 'HomeController:login') );
Do something like:
$app->addRoutes(array( '/' => array('HomeController:login', $authenticate)) );
Thank you.