将配置存储在数据库中
我的应用程序配置有问题。它基于 KohanaPHP 框架,目前我将配置存储在自定义配置文件中:
$config['status'] = array(
'1' => 5,
'2' => 10,
'3' => 15,
'4' => 20,
'5' => 25,
'6' => 30
);
然后存储在视图/控制器中(需要时):
$arr = Kohana::config('settings.status'); echo $arr[$item->status]
现在我正在寻找在数据库中存储此类配置数组的最佳方法。
你会推荐什么?单独的桌子?将所有内容放在一张表中?你能给我一个建议吗?
干杯, M。
I'm having a problem with my application configuration. It's based on KohanaPHP framework, currently I store configuration in custom config file:
$config['status'] = array(
'1' => 5,
'2' => 10,
'3' => 15,
'4' => 20,
'5' => 25,
'6' => 30
);
and then in view/controller (when needed):
$arr = Kohana::config('settings.status'); echo $arr[$item->status]
Now I'm looking for the best method to store such config arrays in database.
What would you recommend? Separate tables? Putting everything in one table? Would you give me a tip?
Cheers,
M.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Kohana 已经有一个数据库配置读取器/写入器:
类
Kohana_Config_Database
位于数据库模块中。Kohana already has a database configuration reader/writer:
The class
Kohana_Config_Database
is in the database module.这完全取决于这些数组的相似/不同程度。通常,我会说您创建带有 Id、Value 和可能的排序顺序的单独表。您将为每个数组创建一个单独的表,因为即使这些数组可能具有相同的结构,它们也是不相关的。
但是,我到目前为止还无法判断你的这个数组是做什么的。也许最好将其保留在配置文件中,除非您想从其他数据库记录中引用它。
It depends entirely on how similar/different these arrays are. Normally, I'd say you create separate tables with an Id, Value and potentially a sort order. You'd create a separate table for each of these, because these arrays are unrelated even though they may have the same structure.
However, I cannot tell by far what this array of yours does. Maybe it's better to just leave it in the config file, unless you want to refer to it from other database records.