2011-09-07 74 views
0

我需要将数据添加到在Drupal 7时间字段我试着使用日期字段添加数据连接到一个节点在Drupal 7

$node->field_test_a_updated[0]['value'] = $val; 
$node->field_test_a_updated[0]['delta'] = 0; 
$node->field_test_a_updated[0]['timezone'] = 'UTC'; 
$node->field_test_a_updated[0]['timezone_db'] = 'UTC'; 
$node->field_test_a_updated[0]['date_type'] = 'datetime'; 

其中$ VAL的值为“2010- 06-15T00:00:00-00:00" 。

当我尝试导入内容时,附加到该节点的所有其他字段都得到正确迁移,但日期字段除外。我也尝试使用[LANGUAGE_NONE]选项。

我相信我错过了与drupal7字段api有关的东西。

请帮助。

回答

0

在Drupal 7场(在这方面)的结构是:

array(
    'language_code' => array(
    0 => array(
     'value => $val, 
     'other_column_value' => $other_val 
    ) 
) 
); 

delta由每个内部$array['language_code']这样你就不会需要包括它的阵列的关键处理。你的情况,你想要的代码看起来像这样(假设当然你传递的节点通过node_save()之后):

$node->field_test_a_updated[LANGUAGE_NONE] = array(
    0 => array(
    'value' => $val, 
    'timezone' => 'UTC', 
    'timezone_db' => 'UTC', 
    'date_type' => 'datetime' 
) 
); 

希望帮助