Setting and retrieving session data

+
0
-

So, my user registration and login works fine. (Thanks Jiri).

When a user logs in, I wish to set some session data related to the user.

I have been following the example on https://doc.nette.org/…ttp/sessions

So, in my user constructor, I set the session, and section variables..

public function __construct(Nette\Database\Context $database, UserModel $userModel, UserProfileModel $userProfileModel, Nette\Http\Session $session)
{
        $session->start();
        $this->session = $session;
        $this->database = $database;
        $this->userModel = $userModel;
        $this->userProfileModel = $userProfileModel;
        $this->sessionSection = $session->getSection('userSection');

        $path = __DIR__.'/../../layouts/@common.latte';
        $this->setLayout( $path );
}

Then in my startup() method, I start the session.

public function startup()
{
        parent::startup();
        $this->session->start();
        $sessionId = $this->getSession()->getId();
}

This is repeated in my blog constructor…

public function __construct(BlogModel $blogModel, Nette\Http\Session $session)
{
        $this->session = $session;
        $this->blogModel = $blogModel;
        $path = __DIR__.'/../../layouts/@common.latte';
        $this->setLayout( $path );
}

And similarly in the startup() method.

public function startup()
{
        parent::startup();
        $this->session->start();
        $sessionId = $this->getSession()->getId();
}

In my user::loginFormSucceeded() method, the session data is set.

$this->sessionSection->user = $this->userProfileModel->getUserProfileByEmail($values->email);

However, the session data does not seem to be set in blog presenter.

Where am I going wrong here?

However, I am unable to seen

Last edited by kevin.waterson@gmail.com (2020-07-10 11:54)