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.

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

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面