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

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

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

问题描述

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



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



也许我必须调用其他一些功能来保存CCK字段?或者这个设置可能有问题?

解决方案

我相信该字段是

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

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

08-22 22:29