基于Codeigniter数据库的配置设置 [英] Codeigniter Database Based Configuration Settings

查看:46
本文介绍了基于Codeigniter数据库的配置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Codeigniter 2.0的最新副本来构建应用程序。我的应用程序是动态的,有点像自定义CMS,我想您可以说。我有一个名为设置的数据库表,其中包含以下字段:

I am building an application using the latest copy of Codeigniter 2.0. My application is dynamic and is kind of like a custom CMS I guess you could say. I have a database table called 'settings' with the following fields:


  • id

  • name


基本上,我目前正在使用辅助函数来从中检索特定设置我的设置表,例如网站名称或当前主题。但是,我开始认为,数据库中用于获取设置的恒定数量的调用可能会过多。

Basically what I am currently doing is using a helper function to retrieve specific settings from my settings table like the site name or current theme. However I've started thinking that maybe the constant amount of database calls for retrieving settings is a bit too much on the database.

是否有一种方法可以检索我的设置数据库中的应用程序,然后将它们附加到我的配置文件中?我注意到Mojomotor做了类似的事情,它是CI 2.0应用程序,但是我宁愿用最简单,最简单的代码来做到这一点。

Is there a way of retrieving settings for my application from the database and then appending them to my configuration file? I've noticed Mojomotor does something similar and it is a CI 2.0 application, however I would much rather the simplest and easiest code to do so.

我最好希望能够经常检查数据库中的设置是否已更改并更新配置文件。对数据库的压力越小越好。

I would preferably like to be able to check every so often if a setting in the database has changed and update the configuration file. The less strain on the database the better.

推荐答案

最好的解决方案在中间。数据库调用不为零;而不是每个设置一个数据库调用。而是每个页面加载一次数据库调用,并获取记录集/对象中的所有设置,您的应用程序的其余部分可以根据需要进行引用。

The best solution lies in the middle. Not zero DB calls; and not one DB call per setting. Do one DB call per page load instead, and get every setting in a recordset / object that the rest of your app can refer to as needed.

这篇关于基于Codeigniter数据库的配置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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