[英]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.