How to edit a session after create a session

Hi,

I want to add another item to my session after that this session is create. I have this :

private function _registerSession($user, $account)
{
    $this->session->set('auth', array(
        'user_id' => $user->id,
        'username' => $user->name
    ));
}

And in another controller I want to edit this session for example :

$auth = $this->session->get('auth');
$auth->add('account_id', '10');

How this is possible to do that ?

$auth = $this->session->get('auth');
$auth->add('account_id', '10');
$this->session->set('auth', $auth);

https://docs.phalconphp.com/en/latest/reference/session.html#storing-retrieving-data-in-session



13.9k

Thanks for your answer. add() method doesn't exist then i'm using this :

$auth = $this->session->get('auth');
$auth['account_id'] = '1';
$this->session->set('auth', $auth);

Phalcon doesn't have any special session handling code - it's just a wrapper for the built-in session functionality. Since $_SESSION is a superglobal, this wrapping functionality tends to get in the way more than help. In this case, I would just do:

$_SESSION['auth']['account_id'] = 1;