Creating Drupal CCK content programmatically/ via API

大兔子大兔子 提交于 2019-11-30 14:43:57

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

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

Drupal doesn't provide any "cascading" save mechanism to save a hierarchy of nodes in one swoop. You'll need to build each node in code and call node_save() on it explicitly as described by Phil Carter.

The Node Export module can generate sample code for creating a node (complete with CCK fields) programatically.

There are a ton of modules that try to do the import thing right. Take a look at a comparison of them http://groups.drupal.org/node/21338

If you need strategies or examples of importing stuff into nodes, those are a great resource.

I don't think "creating" these programs is even necessary.

Why not just display a list of exercises that match your requirements and share 'characteristics' with the user.

I'd accomplish this by making the 'characteristics' be taxonomy. Then attached to users either with a profile, or taxonomy flag. Then display a list (perhaps even a view at first) and those with the same characteristic tags within exercises.

This would be dynamic and user specific and note require pre-loading a bunch of programmes.

A thought.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!