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
在Drupal7中以编程方式添加注释_Drupal_Drupal 7 - Fatal编程技术网

在Drupal7中以编程方式添加注释

在Drupal7中以编程方式添加注释,drupal,drupal-7,Drupal,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@example.com'; $comment->name = 'admin'; $commen

正在尝试在自己的模块中创建注释

$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@example.com';
$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);
该代码导致以下错误:

致命错误:在中调用未定义的函数节点加载() 第1455行的BLA/BLA/comment.module

node_load()函数位于节点模块中,当然,该模块已启用

如何修复它

谢谢

试着这样做:

  $comment = (object) array(
    'nid' => $node_id,
    'cid' => 0,
    'pid' => 0,
    'uid' => 1,
    'mail' => '',
    'is_anonymous' => 0,
    'homepage' => '',
    'status' => COMMENT_PUBLISHED,
    'subject' => 'dsk subject',
    'language' => LANGUAGE_NONE,
    'comment_body' => array(
      LANGUAGE_NONE => array(
        0 => array (
          'value' => 'aaa',
          'format' => 'filtered_html'
        )
      )
    ),
  );

  comment_submit($comment);
  comment_save($comment);

Wierd…将模块文件夹移动到系统模块目录中,错误消失了。解决了的!你把代码放在哪里?我在这里测试了它,它工作得很好,但是如果节点加载未定义,那么您的代码必须在节点模块之前执行。您不应该将自定义模块或社区模块放在核心模块文件夹中。