Sessions in CakePHP4

Session Variables in CakePHP4

Getting the session variable in a view:

$this->getRequest()->getSession()->read('Auth')['id'];

 

Getting the session in a controller:

$session = $this->request->getSession();
$session = $this->getRequest()->getSession();

 

Reading the session Auth:

Note: using the Authentication class is the preferred method for retrieving user information.

$session = $this->request->getSession();
debug($session->read('Auth'));

 

Writing Session Variables:

$session = $this->request->getSession();
$session->write('AdminGrantApplications.search_word', $someVariable);

Share this Post