Drupal 5:自定义内容类型中的 CCK 字段
我有一个通过 NodeAPI 挂钩(hook_insert
、hook_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信该字段
在 Drupal 6 中就是这样,它不遵循字段的实际名称或表字段名称。查看该字段的简单方法是填写一个节点,然后将其转储以查看其结构。这将为您提供在 node_save 中期望的名称。我已经有一段时间没有使用 Drupal 5 了,但你也离得不远了。你很接近。
I believe the field is
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.