加载节点的先前版本
当你得到一个节点时,如何加载之前的版本(修订版)?
我知道如何加载修订版,但不知道如何获取先前的修订版号($node->vid 是当前修订版)。
谢谢
When you get a node, how do you load the previous version (revision)?
I know how loading a revision but not how getting the previous revision number ($node->vid is the current revision).
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设你有一个节点对象
$node
,你可以使用下面的代码来获取之前的版本。获得先前版本后,您可以使用
node_load(array('nid' => $node-nid, 'vid' => $previous_vid))
加载新节点对象。该代码应检查
db_result()
是否返回FALSE
(如果没有先前的修订版本)。需要注意的是,字段
vid
对于每个节点来说都是全局的;它不包含不同节点的相同值。Supposing that you have a node object
$node
, you can use the following code to get the previous revision.Once you have the previous revision, you can load the new node object with
node_load(array('nid' => $node-nid, 'vid' => $previous_vid))
.The code should check if
db_result()
returnsFALSE
, in the case there isn't a previous revision.To note that the field
vid
is global for each node; it doesn't contain the same value for different nodes.谢谢大家。
我还找到了另一个解决方案:
但是如果你有很多修改,你会得到一个大数组。
Thanks all.
I found also an other solution:
But if you have a lot of revision you get a big array.
如果我明白你想做什么;您想在有人提交更改后获得节点的预览吗?
预览按钮有自己的提交处理程序,
node_form_build_preview ()
。在那里,它使用$form_state
中的数据创建一个新的节点对象并运行node_preview()
,它返回预览的标记。如果您想在用户单击预览按钮时捕获预览,则需要使用
hook_form_alter
将另一个提交处理程序添加到预览按钮:其中 mymodule_custom_preview 是自定义提交函数的名称。看看
node_form_build_preview()
作为指导,但您的提交函数将如下所示:另请参阅
node_form()
,它让您了解节点表单的结构。完成后,您的模块中将包含如下所示的代码:If I understand what you're trying to do; you want to get the preview of the node after someone submits changes?
The preview button has its own submit handler,
node_form_build_preview()
. There, it creates a new node object using the data in$form_state
and runsnode_preview()
, which returns the markup for the preview.If you want to capture that preview when the user clicks the preview button, you'll need to use
hook_form_alter
to add another submit handler to the preview button:where mymodule_custom_preview is the name of your custom submit function. Take a look at
node_form_build_preview()
for guidance, but your submit function is going to look something like this:Also take a look at
node_form()
, which gives you an idea of how the node form is structured. When you're all done, you're going to have code in your module that looks something like this: