以编程方式/通过 API 创建 Drupal CCK 内容 [英] Creating Drupal CCK content programmatically/ via API

查看:29
本文介绍了以编程方式/通过 API 创建 Drupal CCK 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Drupal 6.x 系统创建练习/个人训练计划,并且正在使用内容类型为练习"和程序"的 CCK,其中程序"包含一些标题字段和对练习的节点引用列表它包括.这很好用,我可以手动创建运行良好的程序.我现在想创建一个模块,可以根据我开发的一些算法自动生成这些程序,过程如下:

I am working with a Drupal 6.x system to create exercise / personal training programmes, and am using the CCK with content types of Exercise and Programme, where Programme contains a few header fields and a list of node references to the exercises it consists of. This works great and I can manually create programmes which work fine. I now wish to create a module which can generate these programs automatically based on a number of algorithms I have developed, the process will look like:

  1. 将所有练习加载到数组中
  2. 加载用户个人信息(之前输入)
  3. 建立最适合的练习
  4. 创建新的节目内容类型
  5. 保存程序

一个练习有许多相关的属性,虽然我可以使用 SQL 直接在表中完成上述所有操作,但它会非常复杂并且感觉不对.我想在步骤 1 中将练习作为练习对象数组(node_load?)加载,然后创建一个程序对象并保存.这种 OO 类型的方法是否可行,还是我必须直接操作数据?

An Exercise has a number of related attributes and although I could do all of the above using SQL directly into the tables it would be quite complex and doesn't feel right. I would like in step 1 to load the exercises as an array of Exercise objects (node_load?), and then create a programme object and save. Is this OO type approach possible or do I have to resort to manipulating the data directly?

推荐答案

解决此问题的最佳方法是编写您自己的模块来执行此操作.

The best way to tackle this problem would be to write your own module to do this.

第 1 步你可以对所有的 excercies 做 node_load($nid)第 2 步您可以使用 user_load($uid)第 3 步,您需要遍历用户对象并匹配适当的 excercies.步骤 4/5 我将创建一个新的 $node = stdClass();对象并使用正确的数据填充属性,然后执行 node_save($node);这将为它分配一个 $node->id 等.

Step 1 you can do node_load($nid) on all the excercies Step 2 you can use user_load($uid) Step 3 you'll need to iterate through the user object and match up to the appropriate excercies. Step 4/5 I'd create a new $node = stdClass(); object and populate the attributes with the correct data then perfrom a node_save($node); this will assign it a $node->id etc.

如果您不确定训练程序节点中的属性,请执行 print_r($node);在您已经创建的一个上.

If your unsure on what attributes are in your training program node, then do a print_r($node); on one you've created already.

菲尔

这篇关于以编程方式/通过 API 创建 Drupal CCK 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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