Drupal 5:自定义内容类型中的 CCK 字段

发布于 2024-08-25 22:43:14 字数 551 浏览 5 评论 0原文

我有一个通过 NodeAPI 挂钩(hook_inserthook_update 等)实现自定义内容类型的模块。我想将 CCK 字段添加到此内容类型,并通过 hook_nodeapi 调用(如创建或更新)填充它(以在视图中显示内容节点)。

问题是,我无法访问此内容类型的 CCK 字段。当然,它在“管理字段”页面上启用,但是当我使用 Devel 模块加载此类型的任何节点时,我在节点对象中看不到字段属性 (field_flag)。我可以在“Dev Render”选项卡下看到它作为“content”属性的一部分,例如 $node->content['field_flag']['#value'],但是如果我将值分配给$node->field_flag$node->content['field_flag']['#value'] 并调用 node_save、CCK字段不保存。

也许我必须调用其他函数来保存 CCK 字段?或者这个设置可能有什么问题?

I have module that implements custom content type via NodeAPI hooks (hook_insert, hook_update etc). I want to add CCK field to this content type and populate it via hook_nodeapi calls like create or update (to show content nodes in Views).

Problem is, I cannot access CCK fields for this content type. Sure, it's enabled on "Manage Fields" page, but when I load any node of this type with Devel module, I cannot see field attribute (field_flag) in node object. I can see it under "Dev Render" tab as part of "content" attribute, like $node->content['field_flag']['#value'], but if I assign value to $node->field_flag or $node->content['field_flag']['#value'] and call node_save, CCK fields are not saved.

Maybe I must call some other function to save CCK fields? Or what may be wrong with this setup?

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

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

发布评论

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

评论(1

戈亓 2024-09-01 22:43:14

我相信该字段

$node->field_flag[0]['value']

在 Drupal 6 中就是这样,它不遵循字段的实际名称或表字段名称。查看该字段的简单方法是填写一个节点,然后将其转储以查看其结构。这将为您提供在 node_save 中期望的名称。我已经有一段时间没有使用 Drupal 5 了,但你也离得不远了。你很接近。

I believe the field is

$node->field_flag[0]['value']

It's that way in Drupal 6, it doesn't follow the actual name of the field or table field name. The easy way to see what the field is is to fill out a node, then dump it out to see its structure. That will give you the name it is expecting in node_save. I have not used Drupal 5 in a while, but you can't be too far off. You are close.

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