cakephp session id Empty


cakephp session id Empty

当我执行:pr($this->Session);时,会话id为空我收到:

SessionComponent Object
(
    [__active] => 1
    [__bare] => 0
    [valid] => 1
    [error] => 
    [_userAgent] => 5343528de22b8a6d25e7fd391692c911
    [path] => /profiles
    [lastError] => 
    [security] => medium
    [time] => 800-452-3639
    [sessionTime] => 800-452-3639
    [cookieLifeTime] => 720000
    [watchKeys] => Array
        (
        )
    [id] => 
    [host] => xyz.org
    [timeout] => 
    [enabled] => 1
)

如何启用会话id或创建会话id?

如果您确实需要会话id,则需要启动会话。在before过滤器中试试:

$this->Session->start();
$this->Session->id(session_id());

然后当您执行pr($this->Session->id());时,您将看到新的会话id。

它是由Cake被动处理的-您不需要设置它。只需根据需要调用read(), write()。

$this->Session->write('key', $value);
$value = $this->Session->read('key');

就用

echo $ this ->会话id> ();//打印7gl7bo9gv38rj0sjtqo52dkeu5

在控制器。没有必要使用start()或其他方法。Cakephp(在2.7中进行了测试)会自动为您提供。