2010-05-13 36 views

回答

3

Menu Node module公开了一个API来执行此操作。 您可以阅读代码中的文档(Doxygen)。我认为你需要的功能是由menu_node_get_links($nid, $router = FALSE)方法提供:

/** 
* Get the relevant menu links for a node. 
* @param $nid 
* The node id. 
* @param $router 
* Boolean flag indicating whether to attach the menu router item to the $item object. 
* If set to TRUE, the router will be set as $item->menu_router. 
* @return 
* An array of complete menu_link objects or an empy array on failure. 
*/ 

mlid => menu object关联数组返回。你可能只需要第一个,所以可能看起来是这样的:

$arr = menu_node_get_links(123); 
list($mlid) = array_keys($arr); 

否则,你可以尝试在thread in the Drupal Forums建议:

使用node/[nid]作为$ path参数:

function _get_mlid($path) { 
    $mlid = null; 
    $tree = menu_tree_all_data('primary-links'); 
    foreach($tree as $item) { 
    if ($item['link']['link_path'] == $path) { 
     $mlid = $item['link']['mlid']; 
     break; 
    } 
    } 
    return $mlid; 
} 
+0

看起来像会做到这一点,但我认为SQL是更容易...谢谢,虽然。 – sprugman 2010-05-18 19:03:00

+0

没问题。确实,SQL可能更容易。 :) – sirhc 2010-05-18 19:08:48

6

如果菜单树有多个级别的sql似乎是一个更好的选择。 一个为Drupal 7样品给出波纹管,其中路径是一样的东西“节点/ X”

function _get_mlid($path, $menu_name) { 

$mlid = db_select('menu_links' , 'ml') 
->condition('ml.link_path' , $path) 
->condition('ml.menu_name',$menu_name) 
->fields('ml' , array('mlid')) 
->execute() 
->fetchField(); 
return $mlid; 
} 
+1

辉煌,谢谢。 – 2013-12-05 07:49:25

相关问题