English 中文(简体)
Drupal 7 节点_ save 设定日期
原标题:Drupal 7 node_save set dates

我从 xml 自动创建节点, 我需要为这些节点设定创建日期 。 我尝试了

<?php 
   ...
   $node->created = $date //<- unix timestamp, $node is my node object
   $node->changed = $other_date; 
   ...
?>

but no luck, it sets the current date. Any ideas? Thanks

- Edit -- - 爱迪特 -

$newNode = (object) NULL;
$newNode->type =  blog ;
$newNode->title = $title;
$newNode->uid = 1;
$newNode->status = 1;
$newNode->comment = 0;
$newNode->moderate = 0;
$newNode->sticky = 0;
$newNode->body[ und ][0] = array(
                                 value  => $body,
                                 format  =>  full_html );
$newNode->log      =  Auto Imported Node ;
$newNode->language = LANGUAGE_NONE;

// add fields
$newNode->field_description[LANGUAGE_NONE][0][ value ] = $description;
$newNode->field_byline[LANGUAGE_NONE][0][ value ] = $byline;
$newNode->field_small_image[LANGUAGE_NONE][0][ value ] = $smallimg;
$newNode->field_large_image[LANGUAGE_NONE][0][ value ] = $largeimg;


// save node
$newNode->created = $pd; // i ve tried with commenting this line out, too
$newNode->date = $pd;
node_save($newNode);
最佳回答

它应该为 $node- & gt; 创建 , 但 $node- gt; changed 不能用 Drupal API 设置 。

如果您正在使用 node_submit () 函数, 该函数使用 strtotime ($node- & gt; date) 设置 $node- & gt; created , 您需要将 $node- & gt; date 设置为字符串日期。

$node->date = $date_string;
问题回答

Thx,你说得对! 当我使用:

$node->date =  2005-05-06 08:17:27 ;
node_save($node);

i 在保存后获得 :

[created] => current timestamp
[changed] => current timestamp

但当在节点前添加行时 :

$node = node_submit($node);

i 在保存后获得 :

[created] => 1115360247
[changed] => current timestamp

在节点页面上将显示“创建”日期





相关问题
Get the clicked JSON element s value with ExtJS

I have a JSON store: var jsonstore = new Ext.data.ArrayStore({ fields: [ bla , blubb ], data: [ [ bla , blubb ], [ blabla , blublu ], [ blass , hallo ], ...

JavaScript: DOM text nodes

Take a look at the snippet below. Does it create a text node for the string "test" in the DOM? Can I select that node with jQuery for MooTools? <div id="foobar"> test <img /> </div&...

How to add nodes to a dijit tree on the fly

Basically what I have is a tree with 3 nodes, created like so: for (var i=0; i<response.length; i++) { response[i]["type"] = "project"; } var data = { ...

Drupal anonymous user permissions problem

I have been wracking my brain on how to solve this issue for hours now, and I know I m not the first one to encounter it. I am having trouble granting anonymous users access to node content in Drupal ...

Deleting xml nodes using xslt

Does anyone know how to copy only the first n nodes in a xml file and delete the rest using xslt? So say I only want to copy the first 10 nodes and delete the rest of the nodes that belong to the same ...

Erlang Ets tables between Nodes

I ve got an ejabberd server with a good amount of custom modules running. I have several mnesia tables and I know these can be easily copied between nodes without any change to the code at all. I ...

热门标签