简体   繁体   English

CakePHP 2.1 $this->Session->write 不工作

[英]CakePHP 2.1 $this->Session->write is not working

I included the 'Session' Component and the helper in my AppController.php Now, if I use $this->Session->write('App.testString', 'test);我在我的 AppController.php 中包含了“Session”组件和助手。现在,如果我使用$this->Session->write('App.testString', 'test); the Session is not created, or at least I don't receive the string when I do echo $this->Session->read('App.testString'); Session 未创建,或者至少我在执行echo $this->Session->read('App.testString'); . .

Do I have to change any settings for Sessions to work?我是否必须更改任何设置才能使会话工作?


Inside a controller function I can write and read a session, but if I want to read the session inside a different function (of the same controller) I don't get a value back.在 controller function 中,我可以写入和读取 session,但是如果我想在不同的 function(同一控制器)中读取 session,我不会得到返回值。

I found the solution: By default CakePHP uses the folder which is set in php.ini.我找到了解决方案:默认情况下 CakePHP 使用在 php.ini 中设置的文件夹。 This folder couldn't be accessed in my hosting-environment (and I was not allowed to change the php.ini).在我的托管环境中无法访问此文件夹(并且不允许我更改 php.ini)。

In this situation, you have to change in the core.php where session files are stored.在这种情况下,您必须更改存储 session 个文件的core.php This is what I had before:这是我之前的:

Configure::write('Session', array(
    'defaults' => 'php'
));

I changed it to this one:我把它改成了这个:

Configure::write('Session', array(
    'defaults' => 'cake'
));

This way, cake uses his own tmp-folder to store the session files.这样,cake 使用他自己的 tmp-文件夹来存储 session 个文件。 Also make sure that the tmp folder and his subfolders are writeable.还要确保 tmp 文件夹及其子文件夹是可写的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 $ this-> Session-> destroy()此行在cakephp 2.5中不起作用 - $this->Session->destroy() this line is not working in cakephp 2.5 $this->session->unset_userdata 不起作用? - $this->session->unset_userdata not working? $ this-> Session-> read('Config')在cakephp中不打印任何内容 - $this->Session->read('Config') prints nothing in cakephp Codeigniter $ this-> session-> set_userdata()无法正常工作 - Codeigniter $this->session->set_userdata() not working properly 在Cakephp中,什么是Session-> valid()? - In Cakephp, what is Session->valid()? 如何在 codeigniter 中使用 $this->session->set_userdata 和 $this->session->userdata('adminId') 4 - How to use $this->session->set_userdata and $this->session->userdata('adminId') in codeigniter 4 $ this-> session-> set_flashdata()然后$ this-> session-> flashdata()在codeigniter中不起作用 - $this->session->set_flashdata() and then $this->session->flashdata() doesn't work in codeigniter Session-> flash在CakePHP中未显示会话消息 - Session->flash is not showing session message in CakePHP CakePHP Session-> valid()始终返回false - CakePHP Session->valid() always returns false Codeigniter $ this-> session->…向控制器添加构造函数时未加载(失败) - Codeigniter $this->session->… not loading (failing) when adding constructor to controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM