Search code examples
phpdrupaldrupal-6module

Drupal menu_get_object error (The server closed the connection > without sending any data)


I am using menu_get_object() in my module hook_nodeapi function. Due to that code I get the following error:

Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

The code is as follows:

 function mymodule_nodeapi(&$node, $op, $a3, $a4){    
    $nodex = menu_get_object();
    drupal_set_message("Currnet Node(test) : {$nodex->nid}");
 }

How can I resolve this problem?


Solution

  • I think it's because $node is passed in by reference to the hook_nodeapi() function and you're trying to re-assign it using menu_get_object().

    You should either use a different name for the second node you want to load, e.g.

    function mymodule_nodeapi(&$node, $op, $a3, $a4){    
      $other_node = menu_get_object();
      drupal_set_message("Currnet Node(test) : {$other_node->nid}");
    }
    

    Or, if you're looking for the node to which the nodeapi function is referring to, just use the $node object passed into the function.

    UPDATE

    I think this will do what you're trying to do:

    function mymodule_nodeapi(&$node, $op, $a3, $a4){ 
      // If this call to nodeapi is for the currently visited node page
      // $a3 contains a boolean indicating whether the view mode is teaser of full.
      if ($op == 'view' && !$a3) {
        drupal_set_message('Current Node : ' . $node->nid);
      }
    }