Kohana - 会话数据库
我正在尝试将会话数据库与 Kohana 3 一起使用。
我已经按照此处所述设置了 mysql 数据库: http://kerkness.ca/wiki/doku.php?id=sessions_and_cookies
我正在设置会话变量,如下所示:
Session::instance('database')->set('uid', $user_id);
但是,当我稍后在不同页面上取回数据或刷新时,它会返回 NULL 。
Session::instance('database')->get('uid', NULL);
但如果我把它们放在一起,效果很好......即
Session::instance('database')->set('uid', $user_id);
Session::instance('database')->get('uid', NULL);
关于为什么会发生这种情况有什么想法吗?
我还在我的配置文件夹中设置了 session.php,如下所示:
<?php
return array(
'cookie' => array(
'name' => 'cookie',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'native' => array(
'name' => 'session',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'database' => array(
'group' => 'default',
'table' => 'sessions',
),
);
?>
干杯, 托马斯.
I'm attempting to use the session database with Kohana 3.
I have setup the mysql database as described here: http://kerkness.ca/wiki/doku.php?id=sessions_and_cookies
I am setting session variables like so:
Session::instance('database')->set('uid', $user_id);
However when I go to fetch the data back later on a different page or refresh it returns NULL.
Session::instance('database')->get('uid', NULL);
But if I put them right next to each other it works fine... i.e.
Session::instance('database')->set('uid', $user_id);
Session::instance('database')->get('uid', NULL);
Any ideas as to why this is happening?
I have also setup session.php in my config folder which looks like this:
<?php
return array(
'cookie' => array(
'name' => 'cookie',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'native' => array(
'name' => 'session',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'database' => array(
'group' => 'default',
'table' => 'sessions',
),
);
?>
Cheers,
Thomas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 session.php 文件更新为如下所示:
问题是默认情况下会话称为“会话”。
所以我重命名了每个适配器,它解决了这个问题。
Update the session.php file to look like this:
Problem was by default the sessions are called 'session'.
So I renamed each adapter and it has fixed the issue.