在CodeIgniter中设置全局变量的最佳方法? [英] Best way to setup a variable for Global use in CodeIgniter?

查看:334
本文介绍了在CodeIgniter中设置全局变量的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CodeIgniter,我有用户数据需要以某种方式存储然后更新。



在用户登录时,我只需要获取他们的数据并将其存储在会话中。现在显然的名称和id永远不会改变,但点和注释计数等将根据用户操作从页面改变到页面。



由于这个数据将不断改变,什么是最好的方式来存储它,更新它,并使其可用于我的应用程序?我不知道如果更新会话每次用户执行一个操作是最好的方式,虽然?



我想到可能使用一个CodeIgniter钩子运行一个函数设置一个变量准备使用?



最好的方法是什么?任何想法?



谢谢你,肖恩·詹金斯

解决方案

将数据存储在数据库中?如果您担心效果,可以使用 Memcache APC 来缓存它,但似乎注释计数和点是需要在会话之间持久的数据。



您仍然需要将数据写入数据库以及缓存,但是您可以直接从缓存读取数据,而不是查询。 / p>

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

解决方案

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.

这篇关于在CodeIgniter中设置全局变量的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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