0

I need some help with user settings mechanism for my Yii-based application.

I've created the following db structure to store user settings:

  1. table user with the following fields

    id | username | email | etc.

  2. table settingslist (to store a list of all possible settings with descriptions) with the following fields

    id | code | name | description

  3. table settings (to store all user settings) with the following fields

    id | userid | settingslistcode | value

Now I'm stuck with the form which allows user to change his settings. I had to deal before with the regular models (i.e. for posts, comments, etc.) where every new model had only one row in the database (Post model - id | title | body |) with the certain amount of attributes (fields of the table). But now I need to store user settings in 10-15 rows and I don't know how to apply Yii model mechanism to work with this, so I can retrieve those settings in a single form (so user could change his preferences).

Any suggestions are greatly appreciated.

Thank you!

4

2 回答 2

1

不确定您的表单的标准是什么,但您可以使用以下内容提取特定用户的所有设置。

$criteria=new CDbCriteria;
$criteria->condition="id=".$user->id;
$settings=Settings::model()->findAll($criteria);

然后循环遍历每个构建表单。

foreach($settings as $setting){
    $criteria->condition="code=".$settings->settingslistcode;
    $settingElement = SettingsList::model()->find($criteria);
    ...
}
于 2010-06-11T05:41:44.120 回答
0

好吧,我不确定您是否将他的个人资料的用户设置存储在您的网站或每个帖子/评论中。

设置列表没问题,我们需要定义所有可能的设置选项。然后,如果您为用户存储站点设置,请尝试在 tbl users 中使用一列 ProfileSettings。我通常使用序列化($setting_array())。

如果您存储每个帖子的用户设置,请创建一个 user_post_settings 表和用户相同的 serialize() 想法。因此,一个用户 - 一个帖子 => 一行。

于 2010-06-12T05:42:37.230 回答