Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal 如何以编程方式创建论坛主题?_Drupal_Drupal 6_Forum_Drupal Forms - Fatal编程技术网

Drupal 如何以编程方式创建论坛主题?

Drupal 如何以编程方式创建论坛主题?,drupal,drupal-6,forum,drupal-forms,Drupal,Drupal 6,Forum,Drupal Forms,我刚刚通过下面的链接了解了如何以编程方式创建论坛和容器 但是,无论我是否应该使用node_save()或任何其他选项,都没有看到任何帖子(谷歌)按照专业语法创建论坛主题 请帮帮我,伙计们 谢谢, Edvin论坛主题实际上只是一个节点,因此节点保存是最好的选择,因为所有需要的挂钩都将被调用 以编程方式创建新节点的快速、安全且简单的方法是使用: Drupal 7个示例: 创建新论坛 $forum = new stdClass(); $forum->name = uniqid

我刚刚通过下面的链接了解了如何以编程方式创建论坛和容器

但是,无论我是否应该使用node_save()或任何其他选项,都没有看到任何帖子(谷歌)按照专业语法创建论坛主题

请帮帮我,伙计们

谢谢,
Edvin

论坛主题实际上只是一个节点,因此节点保存是最好的选择,因为所有需要的挂钩都将被调用

以编程方式创建新节点的快速、安全且简单的方法是使用:


Drupal 7个示例:

创建新论坛

    $forum = new stdClass();
    $forum->name = uniqid();
    $forum->description = uniqid();
    $forum->parent = array(0);
    $forum->weight = 0;
    $forum->vid = variable_get('forum_nav_vocabulary', 0);
    taxonomy_term_save($forum);
创建新主题的步骤

    $node = new stdClass();
    // Set the values for the node
    $node->title = "My new forum topic";
    $node->body = "The body of my forum topic.\n\nAdditional Information";
    $node->type = 'forum'; // Your specified content type
    $node->created = time();
    $node->changed = $node->created;
    $node->status = 1; // To have published, else use 0
    $node->comment = 2; // To have active, else use 0
    $node->uid = 1; // UID of content owner
    //Creates topic at the first "forum"
    $node->forum_tid = reset(array_keys(taxonomy_term_load_multiple(array(), 
    array('vid' => variable_get('forum_nav_vocabulary', 0))))); 
    $node->language = LANGUAGE_NONE;
    $node->taxonomy_forums[LANGUAGE_NONE][0]['tid'] = $node->forum_tid;
    node_save($node);
创建主题注释的步骤

    $comment = (object)array(
            'nid' => $node->nid,
            'pid' => 0,
            'cid' => 0,
            'uid' => 1,
            'mail' => '',
            'is_anonymous' => 0,
            'homepage' => '',
            'status' => COMMENT_PUBLISHED,
            'subject' => 'subject test ' . uniqid(),
            'language' => LANGUAGE_NONE,
            'comment_body' => array(
                LANGUAGE_NONE => array(
                    0 => array(
                        'value' => 'Comment Body ' . uniqid(),
                        'format' => 1
                    )
                )
            ),
        );
     comment_submit($comment);
     comment_save($comment);
使用D7实体API

global $user;
$options = array(
'type' => 'forum',
'uid' => $user->uid,
'status' => 1
);
$entity = entity_create('node', $options);
$wrapper = entity_metadata_wrapper('node', $entity);
$wrapper->title = 'Topic Title;
$wrapper->body = 'Topic Body;    
$terms = taxonomy_get_term_by_name ('General discussion','forums'); //names of tid and vid
$wrapper->taxonomy_forums = reset($terms)->tid;
$wrapper->save();
global $user;
$options = array(
'type' => 'forum',
'uid' => $user->uid,
'status' => 1
);
$entity = entity_create('node', $options);
$wrapper = entity_metadata_wrapper('node', $entity);
$wrapper->title = 'Topic Title;
$wrapper->body = 'Topic Body;    
$terms = taxonomy_get_term_by_name ('General discussion','forums'); //names of tid and vid
$wrapper->taxonomy_forums = reset($terms)->tid;
$wrapper->save();