4
試圖在自己的模塊中創建評論。以編程方式在Drupal 7中添加評論
$comment = new stdClass();
$comment->nid = 555; // Node Id the comment will attached to
$comment->cid = 0;
$comment->pid = 0;
$comment->uid = 1;
$comment->mail = '[email protected]';
$comment->name = 'admin';
$comment->is_anonymous = 0;
$comment->homepage = '';
$comment->status = COMMENT_PUBLISHED;
$comment->language = LANGUAGE_NONE;
$comment->subject = 'Comment subject';
$comment->comment_body[$comment->language][0]['value'] = 'Comment body text';
$comment->comment_body[$comment->language][0]['format'] = 'filtered_html';
comment_submit($comment);
comment_save($comment);
該代碼使得以下錯誤:
Fatal error: Call to undefined function node_load() in BLA/BLA/comment.module on line 1455
node_load()函數是在節點模塊其中,當然,啓用。
如何解決?
謝謝!
奇怪......感動模塊文件夾裏去了客場制模塊目錄和錯誤。解決了! – ymakux
你在哪裏放置該代碼?我已經在這裏測試過了,它工作正常,但是如果node_load未定義,那麼您的代碼必須在節點模塊之前執行。您不應將自定義或社區模塊放置在覈心模塊文件夾中。 – vgardner