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.

SessionBags only in Controller available

Refering to http://docs.phalconphp.com/en/latest/reference/session.html#session-bags. I wanted to store data via SessionBag but when i want to access the data from another controller (which was called after the first one) data is gone. To give you a better point of view:

<?php
// SessionController.php:
class SessionController extends BaseController {
  // some code ...
  public function loginAction() {
      $this->persistent->foo = "bar";
      $this->flash->notice($this->persistent->foo);
      // some code ... like loading a form

      return $this->response->redirect();
  }
}
// IndexController.php:
class IndexController extends BaseController {
  public function indexAction(){
      $this->flash->notice($this->persistent->foo); // does not work
  }
}

Am I doing something wrong or did I misunderstood the documentation?

EDIT: Changed example to a more accurate one.



688
Accepted
answer

Hey there. According to the documentation, persistent bags are available only in your current class.

The data added to the session ($this->session) are available throughout the application, while persistent ($this->persistent) can only be accessed in the scope of the current class.

Right above the title

edited Aug '14

The data added to the session ($this->session) are available throughout the application, while persistent ($this->persistent) can only be accessed in the scope of the current class.

Just use $this->session instead of $this->persistent


well, a step slow.



582

Thought that it's just working in the current class. I should've read the docs more carefully ...

Thanks for the answers.