We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Session troubles

I'm trying to store values in the session to be used elsewhere by various views and controllers. problem is, I don't appear to be actually storing any information. So, here's where I setup the session in the bootstrap:

$di->setShared('session', function() {
    $session = new \Phalcon\Session\Adapter\Files();
    $session->start();
    return $session;
});

Later, in the LoginController, I'm trying to stash data in the session:

                    $this->session->set('userid',$user->ID);

but, on further inspection when interrupting the process (and why this data is never stored) I found this when analyzing the login controller's output:

Notice: Trying to get property of non-object in C:\workspace\GIIAnalytics\app\controllers\LoginController.php on line 32

line 32 is the one pasted above. I don't understand what I'm missing here. Any help would be appreciated.

Try this in LoginController

var_dump($this->session, $user);

Check both vars has the right type and tell us



1.1k
Accepted
answer

rookie mistake there, $user was acceually an assoc. array. Thanks.

Try this in LoginController

var_dump($this->session, $user);

Check both vars has the right type and tell us