Cakephp 3如何制作会话数组 [英] Cakephp 3 How to make session array

查看:41
本文介绍了Cakephp 3如何制作会话数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在控制器中编写会话。我的结构是

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

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

我正在尝试

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

但是它不起作用。在cakephp 3中如何实现

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

推荐答案

要在CakePHP 3中的Session中编写变量,您需要编写以下代码:

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

要弄清楚一切:

// 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"] ) );

这篇关于Cakephp 3如何制作会话数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆