Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Session bug? Variable is "forgotten" right after putting in

Im using session through ->getDI and \Phalcon\DI::getDefault()->get('flash') way. But they seems to be different. Services.php:

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

nothing special.

var_dump (\Phalcon\DI::getDefault()->get('flash')->getMessages());
var_dump($this->flashSession->getMessages());
var_dump (\Phalcon\DI::getDefault()->get('flash') == $this->flashSession);

so far its null; null, true. Everything is ok.

$this->flashSession->message('key2', 'val2');
var_dump (\Phalcon\DI::getDefault()->get('flash')->getMessages());
var_dump($this->flashSession->getMessages());

but now, the first dump has the values, while the 2nd DOES NOT! It returns a null.



2.7k
Accepted
answer

The method you use getMessages, removes the messages aswell. But check out the documentation, its 2nd param is called $remove, and it controls if it should remove the messages or not.