$f3->reroute() Clears Flash Messages

89 views
Skip to first unread message

conleec

unread,
Nov 4, 2019, 8:22:28 PM11/4/19
to f3-fra...@googlegroups.com

Has anybody figured out a way to maintain the $_SESSION variable on a redirect, when using Fat Free Framework? Currently, anytime I use a redirect, my Flash Messages get cleared and will not display.

For instance, in the following code, neither message displays:


if ($verifyUser) {
    $this
->createUserSession($verifyUser);
   
if ($_SESSION['user_premium'] == 2) {
       
// Admin, so go to admin dashboard
        $this
->flash->addMessage('You\'re logged in as Administrator.', 'success');
        $this
->f3->reroute('/admin/index');
   
} else {
       
// Regular user, so go to regular dashboard
        $this
->flash->addMessage('You\'re logged in as a registered user.', 'success');
        $this
->f3->reroute('/dashboard/index');
   
}
}

Flash messaging works perfectly when redrawing a page (when validating forms, for instance), but anytime I reroute, the session variable seems to get cleared.

Any thoughts are gratefully accepted.

richgoldmd

unread,
Nov 4, 2019, 8:48:05 PM11/4/19
to Fat-Free Framework
Are you sure session_start() is being called in this particular case?

Instead of checking the session value with $_SESSION[], try using $f3->get('SESSION.user_premium') which will automatically ensure your session is started.

I'm not sure what createUserSession() does, but using the Hive access methods for session ensures that your session is started.

conleec

unread,
Nov 5, 2019, 3:00:18 PM11/5/19
to Fat-Free Framework
Thanks richgoldmd,

I have a couple things to check, and I will definitely look into your suggestion. Slammed at my REAL job today, so probably not until this evening...

Chris
Reply all
Reply to author
Forward
0 new messages