2010-01-05 78 views
2

我已经构建了一组节点。在通过node_save()运行后,我找回了nid,我可以导航到该节点的页面,但它们是空的。 (没有数据显示的任何字段。)Drupal-6:为什么这个节点不会保存?

当我去到编辑网址为节点,我收到此错误信息:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'Bout_node_form' was given in /home/odp/public_html/includes/form.inc on line 367.

这里是一个节点,我尝试print_r()保存:

stdClass Object 
(
    [type] => Bout 
    [name] => Gary Oak 
    [title] => Bout - 0 
    [promote] => 1 
    [comment] => 2 
    [revision] => 
    [format] => 0 
    [status] => 0 
    [field_weapon] => Array 
     (
      [0] => Array 
       (
        [value] => foil 
       ) 

     ) 

    [field_fencer] => Array 
     (
      [0] => Array 
       (
        [uid] => 3 
       ) 

     ) 

    [field_touches_scored] => Array 
     (
      [0] => Array 
       (
        [value] => 4 
       ) 

     ) 

    [field_meet] => Array 
     (
      [0] => Array 
       (
        [nid] => Drew 
       ) 

     ) 

    [field_round] => Array 
     (
      [0] => Array 
       (
        [value] => 1 
       ) 

     ) 

    [field_legacy_bout] => Array 
     (
      [0] => Array 
       (
        [value] => no 
       ) 

     ) 

    [teaser] => 
    [uid] => 1 
    [created] => 1262732370 
    [validated] => 1 
) 

这些节点已全部运行,虽然node_validate(),想必会已经引起一些错误。此外,此节点缺少所需的分类,但这也不会导致任何错误消息。

这是node_validate()如何被调用:

function preview_validate($form, &$form_state) { 
    $nodes_to_save = construct_nodes(); 

    foreach ($nodes_to_save as $node) { 
     node_validate($node, $form); 
     if ($errors = form_get_errors()) { 
      form_set_error('', t('Validation error. No nodes saved.')); 
     } 
    } 

    $_SESSION[CONSTRUCTED_KEY] = $nodes_to_save; 
} 

这是错误是从哪里来的,在核心文件includes/form.inc

// If $callback was returned by a hook_forms() implementation, call it. 
    // Otherwise, call the function named after the form id. 
    $form = call_user_func_array(isset($callback) ? $callback : $form_id, $args); 

节点在node表显示,但不是content_type_bout表。

这是construct_nodes()函数:

function construct_nodes() { 
    global $user; 
    $file = unserialize($_SESSION[FILE_KEY]); 

    $count = 0;   // how many nodes have been created? 
    $success = TRUE; // have all the nodes thus far validated? 
    foreach ($file->parsed as $node) { 
     $odp = new StdClass(); 
     $odp->type = $_SESSION[NODE_TYPE_KEY]; 

     if (! in_array('name', $file->matched_keys)) { 
      $odp->name = $user->name; 
     } 

     if (! in_array('title', $file->matched_keys)) { 
      $odp->title = sprintf("%s - %s", $_SESSION[NODE_TYPE_KEY], $count); 
     } 

     $node_type_default = variable_get('node_options_'. $_SESSION[NODE_TYPE_KEY], array('status', 'promote')); //copied from blogapi module 

     $odp->promote = in_array('promote', $node_type_default); 
     $odp->comment = variable_get('comment_'. $_SESSION[NODE_TYPE_KEY], 2); 
     $odp->revision = in_array('revision', $node_type_default); 
     $odp->format = FILTER_FORMAT_DEFAULT; 
     $odp->status = CTN_DEFAULT_PUBLISHED; 

     // this makes the assumption that the field arrays will always have only one item 
     // doesn't handle taxonomy 
     foreach ($node as $field => $value) { // $field => value:       [Touches scored] => 5 
      $node_key = $file->matched_keys[$field]; // $node_key will be something like: "field_meet" or "vid:4" 
      $vid = vidOfTaxKey($node_key); 
      if ($vid == NULL) { 
       $valTypes = $_SESSION[SAMPLE_NODE_KEY]->$node_key; // like:  [0] => Array ([uid] => 3) 
       $valType = array_keys($valTypes[0]); 
       $odp->$node_key = array(array($valType[0] => $value)); 
      } 
     } 

     $to_save[] = $odp; 
     $count++; 
     unset($submitted_odp); 
    } 
    return $to_save; 
} 

bout是CCK-定义的内容类型。我相信,使用人名“Bout”代替内部代码名称bout是错误的来源。

+0

你是怎么称之为node_validate() – streetparade 2010-01-05 23:16:24

+0

请显示第367行是 – streetparade 2010-01-05 23:18:27

+0

以上澄清 – 2010-01-06 00:23:36

回答

4
  1. 这是自定义内容类型定义在哪里?在custom module中,或通过管理>内容>内容类型>添加内容类型?它是否定义?如果没有,那么难怪你会得到这个错误:Drupal应该怎么知道这个内容类型是由什么组成的?以及如何渲染它的视图和编辑表单?尝试定义它,无论哪种方式。

  2. 自定义内容(节点)类型名称([type] => Boutmust contain only lowercase letters, numbers, and underscores。尝试将Bout更改为bout

另请参阅How do I create a node from a cron job in drupal?http://drupal.org/node/178506#comment-895418(整个线程)。

+0

它看起来像#2是答案,但我还没有完全解决这个问题... http://stackoverflow.com/questions/2151015/drupal-6-why-cant-a-post-be-referenced – 2010-01-28 00:22:41

+0

请不要针对同一问题提出新问题,但请在此处编辑您的问题,以清楚地说明问题,因为您目前了解该问题。另一个问题将被重复关闭。 – 2010-01-28 05:25:28

0

试试这个

<?php 
$new_blognode = new stdClass(); 
$new_blognode->type = 'blog'; 
module_load_include('inc', 'node', 'node.pages'); 
$output .= drupal_get_form('blog_node_form', $new_blognode); 
?> 

注意,你应该将其更改为您的需求

+0

我不想改变节点的显示或编辑方式 - 我只想保存它并使其正常工作,就像没有以编程方式创建的节点一样。 – 2010-01-06 00:24:55

0

$ node ['type'] ='bout'; NOT $ node ['type'] ='Bout';

确认您没有遇到简单的瓶盖问题。

相关问题