I would like to create a redirect when the user session expires. I know how to do this like so:
$app->before(function (Request $request) {
if (!$request->getSession()->get('displayName')) {
return new RedirectResponse('login', 301);
}
});
The problem is that I get the error : Fatal error: Class 'RedirectResponse' not found in /Applications/MAMP/htdocs/pst/app/bootstrap.php on line 120
I also tried to add this in the if statement:
$app->get('/', function () use ($app) {
return $app->redirect('/hello');
});
but the app variable isn't defined. What is the right way to do this?
UPDATE:
I added the RedirectResponse function from Symfony2. But the displayName isn't correct. I dumped by session, could anyone take a look of what it should be?
DUMP: http://pastebin.com/7XQbJJ08
In my layout.twig (general layout) I have <span> {{ app.user.displayName }}</span>
and after a while no reaction he says he can't find the attribute displayName on a null attribute.