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

Tuesday, January 11, 2022

[FIXED] Cakephp 3 How to make session array

 January 11, 2022     cakephp, cakephp-3.0, cakephp-3.x, session     No comments   

Issue

I am trying to write session in controller. My structure is

$_SESSION['a'][0] = 1;
$_SESSION['a'][1] = 2;
$_SESSION['a'][2] = 3;

And I am trying this

Configure::write('Session', ['a' =>'1'])

But it is not working. How do this in cakephp 3 way


Solution

To write variable in Session in CakePHP 3 you need to write following code :

$this->request->session()->write('Your Key',Your_array);

To know more information you can visit here :

http://book.cakephp.org/3.0/en/development/sessions.html

To make things perfectly clear:

// code writing array to session
$a = [ "abc" => "word", "123" => 42, "?" => $b ];
$a["more"] = "if you need to add";
$a[] = "whatever";
$this->request->session()->write( 'my_array', $a );
// code reading array from session
$recall = $this->request->session()->read( 'my_array' );
debug( sprintf( "What's the word? [%s]", $recall["abc"] ) );


Answered By - Hardik Patel
  • 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