PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 10, 2022

[FIXED] How to read and write Session in Cakephp 3.0

 March 10, 2022     cakephp-3.0, session     No comments   

Issue

I am new to cake 3.0. I have read documentation on http://book.cakephp.org/3.0/en/development/sessions.html But I am not able to write sessions.

use Cake\Network\Session\DatabaseSession;

$session->write('Config.language', 'eng'); 
$session->read('Config.language');

Solution

Update : For CakePHP 3.6+, see @shubham715 answer

The following applies to CakePHP before 3.6 :

You need to set $session :

$session = $this->request->session();
$session->write('Config.language', 'eng'); 
$session->read('Config.language');

And then you'll be able to read and write in your session

Or you can direclty read and write :

$this->request->session()->write('Config.language', 'eng');
$this->request->session()->read('Config.language');


Answered By - Jun
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing