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
Php 如何在Drupal7中为节点设置自定义字段值?_Php_Drupal_Drupal 7 - Fatal编程技术网

Php 如何在Drupal7中为节点设置自定义字段值?

Php 如何在Drupal7中为节点设置自定义字段值?,php,drupal,drupal-7,Php,Drupal,Drupal 7,我正在尝试使用下一个代码从外部脚本添加新节点: define('DRUPAL_ROOT', getcwd()); include_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $node = new stdClass(); $node->title = "Your node title"; $node->body = "The body

我正在尝试使用下一个代码从外部脚本添加新节点:

    define('DRUPAL_ROOT', getcwd());
    include_once './includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
    $node = new stdClass();
    $node->title = "Your node title";
    $node->body = "The body text of your node.";
    $node->type = 'rasskazi';
    $node->created = time();
    $node->changed = $node->created;
    $node->status = 1; // Published?
    $node->promote = 0; // Display on front page?
    $node->sticky = 0; // Display top of page?
    $node->format = 1; // Filtered HTML?
    $node->uid = 1; // Content owner uid (author)?
    $node->language = 'en';
    node_submit($node);
    node_save($node);
但是如何设置自定义字段值(例如“sup_id”整数)?

如下所示:

$node->field_sup_id[LANGUAGE_NONE] = array(
  0 => array('value' => $the_id)
);
如果您的字段具有多个基数,则可以添加以下额外项:

$node->field_sup_id[LANGUAGE_NONE] = array(
  0 => array('value' => $the_id),
  1 => array('value' => $other_id)
);
您可以使用数组的
language
元素定义此特定字段值所属的语言:

$lang = $node->language; // Or 'en', 'fr', etc.
$node->field_sup_id[$lang] = array(
  0 => array('value' => $the_id),
  1 => array('value' => $other_id)
);

在调用
node\u save()
之前添加这些字段,当您调用它时,字段内容将被添加/更新。

Clive就在这里。您也可以使用数组速记语法,这是更好的符号IMHO。。。e、 g

$node->field_sup_id[LANGUAGE_NONE][0]['value'] = "2499";