数据库记录的单独公共版本和编辑模式版本

发布于 2024-10-20 17:05:49 字数 307 浏览 6 评论 0原文

我如何最好地实现数据库记录的编辑模式?

记录(例如博客文章)需要在网站上有一个可见的公共版本,而编辑模式版本正在编辑、预览、重新编辑等。

到目前为止,我想到了两种解决方案

  1. : -列主键,包含 ID 和模式。
  2. 为每种模式使用单独的表,并在它们之间进行复制。

我不可能是第一个需要此功能的人。

这通常是如何完成的?它有名字吗?

我使用 CakePHP,它没有明确支持多列键,但我认为这对我的情况并不重要,因为在用户完成编辑后,我实际上不会有具有相同 ID 的多行。

How would I best implement an edit-mode for a database record?

The record (for example a blog post) needs to have a public version visible on the website while the edit-mode version is being edited, previewed, re-edited, etc.

So far, I have two solutions in mind:

  1. Use a multi-column primary key, with the ID and the mode.
  2. Use separate tables for each mode, and copy between them.

I can't be the first one to need this feature.

How is this usually done? Does it have a name?

I use CakePHP which doesn't explicitly support multi-column keys, but I don't think it matters to my situation, as I won't actually have multiple rows with the same ID after the user is done editing.

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

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

发布评论

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

评论(2

苦行僧 2024-10-27 17:05:49

就数据库而言,您不需要编辑模式。 尤其在网络上——http 是一种不可靠的传输协议。

如果您的用户界面允许编辑,那么您只需编辑并(我假设)单击按钮,按钮“后面”的代码最终将更改的数据作为 UPDATE 语句发送回数据库。如果 UPDATE 语句格式正确,并且编辑者和应用程序有足够的权限,则 UPDATE 将成功,并且数据将被更改。

任何在 UPDDATE 之前读取该特定行的人都会看到旧版本;更新后阅读它的任何人都将看到新版本。 (忽略可能的缓存的影响。)

As far as the database is concerned, you don't need an edit mode. Especially over the web--http is an unreliable transport protocol.

If your user interface allows editing, then you just edit and (I presume) click a button, and code "behind" the button eventually sends the changed data back to the database as an UPDATE statement. If the UPDATE statement is formed correctly, and if the editor and application have sufficient permissions, the UPDATE will succeed, and the data will be changed.

Anyone who reads that particular row before the UPDDATE will see the old version; anyone who reads it after the UPDATE will see the new version. (Ignoring the effect of possible caching.)

沉溺在你眼里的海 2024-10-27 17:05:49

听起来您正在寻找版本控制系统或创建帖子的能力,并且在得到管理员批准之前不会使其生效。我不认为这是 cakePHP 原生的,但你可以做的是,

复制控制器中的编辑功能 - >复制 - >重命名,然后对编辑视图执行相同的操作,然后创建一个名为 edits 的新数据库表。还为“保存”或“发布”创建一个下拉框

然后,当按下提交按钮时,您可以通过查看 $this->data 中的数据来决定帖子将填充哪个数据库表。

我认为这将是最简单的方法,因为复制编辑功能,您不必担心将帖子的 id 发送到该功能,蛋糕会自动执行此操作。所以你的帖子表和编辑表的 id 应该匹配。

It sounds like you are looking for a versioning system or the ability to create a post and not make it live until it is approved by an admin. I do not think this is native to cakePHP but what you could do is,

Copy the edit function in the controller->duplicate->rename then do the same for the edit view, then create a new db table called edits. Also create a dropdown box for "save" or "publish"

Then when the submit button is pressed you can decide which db table the post will populate by viewing the data in $this->data.

I think this would be the easiest way since duplicating the edit function you will not have to worry about sending the id of the post to the function, cake will do it automatically. so your id's for the posts table and the edits table should match up.

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