Best way to setup a variable for Global use in CodeIgniter?

痞子三分冷 提交于 2019-12-19 10:28:30

问题


I'm using CodeIgniter and I have user data that needs to be stored in some way then updated. Basic things like name, id, points, comment count etc

At the moment when the user logs in I simply get their data and store it in a session. Now obviously the name and id would never change, but the Points and Comment count etc will change from page to page depending on the user actions.

As this data will be constantly changing, what would be the best way to store it , update it and make it available throughout my app? I'm not sure if updating the session every time the user performs an action is the best way though?

I thought about maybe using a CodeIgniter hook to run a function that sets up a variable ready for use?

Whats the best way? Any ideas?

Thanks, Sean Jenkins


回答1:


Why can't you store the data in a database? If your worried about performance you could use something like Memcache or APC to cache it but it seems like comment count and points are data that need to persist between sessions.

You would still need to write the data to the database as well as the cache but then you could read the data directly from the cache instead of querying for it.



来源:https://stackoverflow.com/questions/8313174/best-way-to-setup-a-variable-for-global-use-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!