开发者

Storing configuration in database

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.


Kohana already has a database configuration reader/writer:

// In bootstrap.php
Kohana::$config->attach(new Kohana_Config_Database);

The class Kohana_Config_Database is in the database module.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜