且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-12 08:02:45

我相信该字段是

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

这样在Drupal 6中,它不遵循字段或表字段名称的实际名称。查看字段的简单方法是填写一个节点,然后将其转储出来查看其结构。这将给你在node_save中预期的名称。我一段时间没有使用Drupal 5,但是你不能太远。你很近。


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?

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.