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

问题描述

我正在使用Drupal 6.x系统来创建运动/个人培训计划,并且正在使用具有运动和程序的内容类型的CCK,其中程序包含几个标题字段和节点参考列表它包括。这很好,我可以手动创建可以正常工作的程序。我现在希望创建一个可以根据我开发的一些算法自动生成这些程序的模块,过程如下:


  1. 将所有练习加载到数组中

  2. 加载用户个人信息(以前输入)

  3. 建立最适合的练习

  4. 创建新程序内容类型

  5. 保存程序

练习具有多个相关属性尽管我可以使用SQL直接在表中执行上述所有操作,但这将非常复杂,并且感觉不对。我想在第1步中将练习作为一个运动对象数组(node_load?)加载,然后创建一个程序对象并保存。这种OO类型的方法是否可行,或者我必须直接操纵数据?



谢谢

解决方案

解决这个问题的最好方法是编写自己的模块来执行此操作。



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



如果您对培训程序节点中的属性不确定,那么请执行一个print_r($ node);在你已经创建的一个。



Phil


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. Load all exercises into array
  2. Load users personal info (entered previously)
  3. Establish best suited exercises
  4. Create new programme content type
  5. Save programme

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?

Thanks

解决方案

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

Step 1 you can do node_load($nid) on all the excerciesStep 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.

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

Phil

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

08-22 23:22