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 error

Am setting up a session in a controller function using the following;

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

    but when I run var_dump($session->getId());exit; within the functionI get the following errors;
    1.Notice: Undefined variable: di in 
    2.Fatal error: Call to a member function setShared() on a non-object in

My objective is to start a session with will be active in the whole application.

Thanks for the help



2.3k
Accepted
answer

If you are in a controller function you have to use $this->getDi()->setShared(...)

If you are in a controller function you have to use $this->getDi()->setShared(...)

Thanks alot. This has sorted my errors but now when I dump $this->session null value is returned

edited Nov '14

For me it works if I set it in controller method and dump it afterwards.

Maybe because I used $di = new FactoryDefault() in my services.php config file.