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

查看:162
本文介绍了CakePHP 2.1 $ this-> Session-> write不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppController.php中包含了'Session'组件和帮助器
现在,如果我使用 $ this-> Session-> write('App.testString' 'test); 没有创建会话,或者至少我不会收到字符串,当我做 echo $ this-> Session-> read .testString');

I included the 'Session' Component and the helper in my AppController.php Now, if I use $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');.

我必须更改工作阶段的任何设定吗?

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.

推荐答案

我找到了解决方案:默认情况下,CakePHP使用在php.ini中设置的文件夹。此文件夹无法在我的主机环境中访问(我不允许更改php.ini)。

I found the solution: By default CakePHP uses the folder which is set in php.ini. This folder couldn't be accessed in my hosting-environment (and I was not allowed to change the php.ini).

在这种情况下,您必须更改存储会话文件的 core.php 。这是我以前的:

In this situation, you have to change in the core.php where session files are stored. This is what I had before:

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

我将其更改为:

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



<还要确保tmp文件夹及其子文件夹是可写的。

This way, cake uses his own tmp-folder to store the session files. Also make sure that the tmp folder and his subfolders are writeable.

这篇关于CakePHP 2.1 $ this-&gt; Session-&gt; write不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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