执行activitylist/log的方式/编码方法

发布于 2024-11-27 03:23:59 字数 494 浏览 0 评论 0原文

好吧,这个问题与编码过程无关,而更像是一种良好而干净的方式来编码此活动列表,我计划构建..

此活动列表将包含页面上的所有活动。

因此,基本上,对于页面上进行的所有操作,它都会调用类似函数 insertActivity($stuff) 的函数来插入有关该操作的活动,例如您刚刚做了某件事。

现在我想知道编码方式,我该怎么做?

我应该在 db 的行中显示“你刚刚做了某事”消息,还是应该在我的 php 文件中定义数字 1 代表“你刚刚做了某事”?

如果消息未存储在数据库中,将帮助我稍后编辑所有活动消息的消息,例如,如果消息应更改为“你刚刚吃了一些东西”。

我应该像我之前所说的那样在操作保存之前/之后调用函数,将此操作记录到活动列表中,还是使用任何其他首选方法来执行此操作?

我的想法只是 insertActivity() 应该通过它得到的输入($stuff)将活动插入数据库。

真的很欣赏简单干净的编码方式来做到这一点。

Ok so this question is not so much about the coding procedure, but more like a good and clean way to code this activitylist, i plan to build..

This activitylist will contain all activities on the page.

So basically on all the actions made on the page, it will call something like a function insertActivity($stuff) to insert the activity about that e.g you just did something.

Now I am wondering the coding way, how should I do it?

Should I have the message "you just did something" in the row in db or should i have numbers where in my php file i define that number 1 stands for "you just did something"?

With message not stored in db will help me editing the message for all the activitymessages later, e.g if the message should be changed to "you just ate something".

Should i do it like i said previously about calling a function before/after the action saves, to log this action into the activitylist, or any other prefferable way to do it?

What i had in mind was just that insertActivity() should just insert the activity to the database, by the inputs ($stuff) it got.

Really appreciate a simple and clean coding way to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

纵性 2024-12-04 03:23:59

那是……一个不可能的问题。之所以不可能,是因为很难回答,也不是不可能,因为不可能给出一个好的答案,之所以不可能,是因为有很多很多不同的好答案,但没有“正确”的答案。

关于拥有两个表有很多话要说,一个仅用于描述,另一个有一个外键,它将引用描述 ID。检索值就像这样简单:

SELECT -- your other columns can go here.
       (SELECT DESCRIPTION FROM DESCRIPTIONS DE 
            WHERE DE.ID = DID.DESCRIPTION_ID LIMIT 1) as ACTIVITY
            -- I always add a LIMIT in a sub-query...
       -- your other columns can go here.
       FROM DID_THINGS DID WHERE USER_ID = 1;

如果活动数量相当有限(并且这些活动是事先已知的),MySQL 会使这种类型的结构变得更容易——您应该查看 ENUM 类型。然而,对于 ENUM,这成为修改站点的最烦人的方式。就我个人而言,我喜欢第二个表选项并且我经常使用它。如果我想拥有它,以便管理员可以添加诸如“您观看了某些内容”之类的内容,我可以简单地通过网络表单公开该内容,并将数据库的珍贵密钥隐藏在没有人知道的地方,包括我。

另一种常见的处理方式是简单地使用关联数组(或散列,或其他)。这样做的好处是可以不涉及数据库连接,非常简单,测试和调试也非常容易和明显。由于这些(除其他外),在国际化脚本中使用它是很常见的。问题是,为了向这些数组之一添加某些内容,您需要实际修改该文件,然后将该文件重新部署到该站点的所有版本。现在,这通常是一件非常简单的事情,但却是一个额外的步骤。允许用户添加到列表中是非常困难的(尽管并非绝对不可能),并且一旦输入数据就进行编辑就更烦人了。

That is... an impossible question. It isn't impossible in the fact that it is difficult to answer, it isn't impossible in that it is impossible to give a good answer, it is impossible because there are many, many different good answers and no "right" answers.

There is a lot to be said about having two tables, one is just for descriptions, the other is has a foreign key which will reference a description ID. Retrieving the value is as simple as:

SELECT -- your other columns can go here.
       (SELECT DESCRIPTION FROM DESCRIPTIONS DE 
            WHERE DE.ID = DID.DESCRIPTION_ID LIMIT 1) as ACTIVITY
            -- I always add a LIMIT in a sub-query...
       -- your other columns can go here.
       FROM DID_THINGS DID WHERE USER_ID = 1;

MySQL makes this type of structure a little bit easier if there are a reasonably finite number of activities (and those are known beforehand) -- you should look into the ENUM type. With ENUM's, however, that becomes the most annoying way of modifying the site. Personally, I like the second table option and I use it very frequently. If I want to have it so that an admin can add something like "You watched something," I can simply expose that via a web form and keep the precious keys to the database hidden away where no-one knows them, including me.

Another frequent way of doing things is to simply have an associative array (or a hash, or whatever). The benefit of this is that it may not involve a database connection, it is very simple and it is very easy and obvious to test and debug. Because of these (among others), it is very common to find this used in the internationalization scripts. The problem is that in order to add something to one of those arrays, you will need to actually go, modify the file, and then re-deploy the file to all versions of the site. Now, often this is something trivially simple, but it is an extra step. It is very difficult (though not strictly impossible) to allow a user to add to the list, and it is even more annoying to edit the data once entered.

风向决定发型 2024-12-04 03:23:59

仅存储操作的 id 是个好主意。您还可以创建“操作”表,在其中存储所有可能的操作。

这样您就可以节省一些磁盘空间并使解决方案更加灵活。

您应该在执行操作后记录该操作。这样您就可以验证操作是否成功。

这个问题很笼统,所以很难提供更具体的答案。如果您需要帮助做其他事情,请提供更多信息。

Storing just id of an action is good idea. You can also create "actions" table where you will have stored all possible actions.

This way you will safe some disk space and make the solution more flexible.

You should log the action after the action was made. This way you can validate if the action was successful or not.

The question is very general, so it's hard to provide more concrete answer. Provide more information if you need to help with something else.

欲拥i 2024-12-04 03:23:59

这取决于

  • 是否有数百万行?
  • 你关心磁盘空间吗?
  • 用户有机会看到该日志吗?

您应该查看这些依赖关系并考虑一下。

It depends

  • will be there millions of rows?
  • do you care about disk space?
  • will have user chance to see that log?

You should look at those dependencies and think about it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文