Drupal 5:自定义内容类型中的 CCK 字段 [英] Drupal 5: CCK fields in custom content type

查看:28
本文介绍了Drupal 5:自定义内容类型中的 CCK 字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

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

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.

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

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

推荐答案

我相信这个领域是

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

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

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.

这篇关于Drupal 5:自定义内容类型中的 CCK 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆