Home  >  Article  >  Backend Development  >  Yii2中数据模型问题

Yii2中数据模型问题

WBOY
WBOYOriginal
2016-06-06 20:24:331004browse

RT,刚开始用Yii2,现在想把一些个默认的数据保存在数据表中(setting),如站点信息、模板设置等,表分为俩字段 key => value,我现在的代码是:

写一个 Setting ActiveReocrd 放入 common\models 中;
然后几个站点信息、模板设置这几个都设置为 Model,主要为为了表单和验证。

请问,怎样的方式是否主流和优雅?如果不是,请大家提点。

回复内容:

RT,刚开始用Yii2,现在想把一些个默认的数据保存在数据表中(setting),如站点信息、模板设置等,表分为俩字段 key => value,我现在的代码是:

写一个 Setting ActiveReocrd 放入 common\models 中;
然后几个站点信息、模板设置这几个都设置为 Model,主要为为了表单和验证。

请问,怎样的方式是否主流和优雅?如果不是,请大家提点。

首先不要重复造轮子,除非你造的轮子更加优秀。

现在想把一些个默认的数据保存在数据表中(setting),如站点信息、模板设置等,表分为俩字段 key => value

这个功能可以使用现成的: https://github.com/funson86/yii2-setting

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn