dongwei1921 2014-10-08 10:41
浏览 103
已采纳

使用Cookie记住Laravel中的用户设置

Previously i asked about cookies in Laravel. I quite understand them now, but i'm running into a wall right now.

I want to/ was told to use a Cookie to 'remember' certain settings a user has made to the view.

Why i want to use Cookie:

I have a back-end on my website with a menubar on the left, filling entire height. But by default the menubar is kind of wide (just like mailchimp has), so i have created a button where the use can narrow the menubar. But, when the user narrows the menubar and goes to another page in the back-end, the menubar resets itself to the default width. I would like my website to 'remember' which kind of menubar the user likes best.

Now, i know how to make a Cookie, i know how to pass it to the next page but, what i do not know and would like to know is: How can i 'trigger' the cookie if the user presses the button to narrow the menubar?

Should this be done in the javascript used to make the narrow button work? I really don't know. I don't want to get some complete code or whatsoever, i just like some input from you guys on how do you do this or how would you do this.

  • 写回答

1条回答 默认 最新

  • douduxia1551 2014-10-10 09:50
    关注

    I would use ajax, on button (settings) click send a post request to your controller which will make a Cookie response.

    If you don't want to force a refresh after for the cookie response you can either cheat and use a '302' type response or else just queue the cookie make. Laravel will perform the cookie make on the next response automatically for you.

    If I may make an extra suggestion:

    I would actually save this in database too and use memcache to load the settings from memory.

    Jereon, please let me know if you need code examples for any of the above. I 'll be happy to prepare them for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图