刷新时的会话变量 [英] Session variable on refresh

查看:61
本文介绍了刷新时的会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的laravel控制器:

I have laravel controller like this:

public function postSessionTopic() {

    $article_id = Input::get('article_id', 0);
    $comment_id = Input::get('comment_id', 0);

    \Session::set('page_topic_id', $article_id); 
    \Session::set('page_comment_id', $comment_id); 

    \\comment - I have tried \Session::put too, but that doesn't change anything


}

当用户点击文章时,我会使用它.我在此控制器中打印出我的会话变量,一切看起来都很好.但是之后,我刷新了页面,并在那里从会话中读取了值,有时它会加载旧值或什么都不加载.我不明白为什么,因为在控制器中我可以看到保存了正确的值!

I use it, when user click on a article. I print_r out my session variable in this controller and everything looks fine. But after that I refresh my page, and there I read value from session, and sometimes it load old value or doesn't load anything. I can't understand why, because in controller i can see, that correct value is saved!

在我的页面中,我得到的值是这样的:

In my page, i get that value like this:

\Session::get('page_topic_id', 0)

推荐答案

这可能不是您的问题,但是如果您将laravel会话存储在数据库中,则将限制该值的大小. Laravel会话迁移具有一个称为有效载荷"的字段,该字段是文本类型.如果超出该字段的限制,则整个会话将被终止.这是我发生的事情,因为我正在向会话中动态添加json模型数据.

This is probably not your issue but if you are storing your laravel session in the database their is a limit on how large that value can be. The Laravel session migration has a field called "payload" that is a text type. If you exceed the limit on that field the entire session gets killed off. This was happening to me as I was dynamically adding json model data to my session.

    Schema::create('sessions', function (Blueprint $table) {
        $table->string('id')->unique();
        $table->text('payload');
        $table->integer('last_activity');
    });

可以容纳多少UTF-8文本在MySQL文本"中字段?

这篇关于刷新时的会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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