drupal menu_get_object错误

drupal menu_get_object错误

问题描述:

我在我的模块hook_nodeapi函数中使用menu_get_object()。由于该代码我得到以下错误:drupal menu_get_object错误

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

的代码如下:

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

谁能帮助我明白是怎么回事,如何解决这个问题,好吗?

我认为这是因为参考hook_nodeapi()函数传递$node,并且您试图使用menu_get_object()重新分配它。

您应该为要加载的第二个节点使用不同的名称,例如,

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

或者,如果你正在寻找到的nodeapi功能是指节点,只需用传递给函数的$node对象。

UPDATE

我认为这会做你想做什么:

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); 
    } 
} 
+0

谢谢!变量名称肯定是一个问题,我纠正了我的代码和上面的代码片断。但不幸的是,我仍然得到同样的错误。该函数应该返回当前正在访问的节点。当我尝试使用参数列表中的$ node时,它会打印多个$ node-> nid's。例如,它们都是按视图列出的页面上的所有节点。 – sisko

+0

@sisko:我已经更新了答案,希望它有帮助 – Clive

+0

非常感谢你的诀窍。请问我可否误解你的解释?我当然不清楚函数$ a3和$ a4在参数列表中的作用。我真的很感激一个简短的解释。不管谢谢! – sisko