简体   繁体   English

Drupal中的node_save在将值存储到MySQL数据库时出现问题

[英]node_save in Drupal has issues while storing the values to MySQL database

I got an issue in node_save in Drupal. 我在Drupal的node_save中遇到了一个问题。

Below is my code: 以下是我的代码:

function retrax_notify_create(){

    $nodeId = array();  
    $nodeObj = new stdClass(); // We create a new node object
    $nodeObj->type = "re_trax_comments_and_notes"; // Or any other content type you want
    $nodeObj->title = "Re-Trax Comments";
    $nodeObj->language = LANGUAGE_NONE; 
    node_object_prepare($nodeObj); // Set some default values.


    $nodeObj->uid = 474; 

        $nodeObj->field_userid_ref['und'][0]['value'] = '5';

        $nodeObj->field_siteid_ref['und'][0]['value'] = '6';

        $nodeObj->field_notify_count['und'][0]['value'] = 7;


    $nodeObj = node_submit($nodeObj); 
    node_save($nodeObj);
    $nodeId[nid] = $nodeObj->nid;

    echo '<pre>';
    print_r($nodeObj);
    return $nodeId;         

}

When I run the hook menu, default values like type , title , uid will be stored in node table and node id will also get generated. 当我运行钩子菜单时, typetitleuid等默认值将存储在节点表中,并且还将生成节点ID。

But the values for other three tables will not get saved for 但是其他三个表的值不会被保存

  • field_data_field_userid_ref field_data_field_userid_ref
  • field_data_field_siteid_ref field_data_field_siteid_ref
  • field_data_field_notify_count field_data_field_notify_count

Database column of one of the tables is shown below 其中一个表的数据库列如下所示

field_userid_ref_value  varchar(255)            Yes NULL    

All the content types are proper but still the value is not being saved to the respective tables. 所有内容类型都是正确的,但仍未将值保存到相应的表中。

What am I doing wrong? 我究竟做错了什么?

I think that lines like: 我认为这样的行:

$nodeObj->field_userid_ref['und'][0]['value'] = '5';

are wrong. 错了。 You have parameter "value" only field type that really have a value, ie text field. 您只有具有值的参数“value”字段类型,即文本字段。 If you have node reference or tag reference fields there should be something else. 如果您有节点引用或标记引用字段,则应该有其他内容。 Probably: 大概:

$nodeObj->field_userid_ref['und'][0]['nid'] = '5';

for nodes, or 对于节点,或

$nodeObj->field_userid_ref['und'][0]['tid'] = '5';

for tags, or 对于标签,或

$nodeObj->field_userid_ref['und'][0]['uid'] = '5';

...for users, depending on what those fields are referencing... ...对于用户,取决于这些字段引用的内容...

Create some node the "common" way, from back-end, then print it and see what fields there exists. 从后端创建一个“常见”方式的节点,然后打印它并查看存在哪些字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM