このシナリオを手に入れたとき、私は質問を受けていました:
ユーザーが何をしたかについて履歴ログを作成する必要があり、もちろんユーザーはさまざまなアクションを実行できます。
私はそれを作るための2つの異なる2つの方法を考えました.正しい方法に従うのを手伝ってくれる人が必要です.
最初の方法:
2 つの異なるテーブルを作成する
- History_user
- History_type
History_userテーブル
id | user_id | history_type (int)
1 1 1
1 3 2
History_type
id | name_action (string)
1 The user has posted on the wall
2 The user has change his profile picture
そして、クエリに参加するだけですHistory_user.history_type = History_type.id
2 番目の方法:
History_user テーブルと Converter というヘルパー サンプルを作成します。
<?php
class Converter {
function history($type_history) {
switch($type_history) {
case 1:
$human_history = "The user has posted on the wall";
break;
case 2:
$human_history = "The user has change his profile picture";
break;
}
return $human_history;
}
}
$converter = new Converter();
$converter->history(1);
パフォーマンスと保守性の観点から、それを行うためのより良い方法を探していました。ありがとうございました。