2014-09-01 65 views
0

我在我的drupal安装中有一个URL:domain.com/content/travel。Drupal 7 - 如何获取菜单线索?

在D6我用下面的代码,以提取由上述线索“旅行”:

$menuParent = menu_get_active_trail(); 
$path = $menuParent[1]['page_arguments'][0]->path; 
$pathArray = explode('/', $path); 
$menuParent = $pathArray[1]; 
$menuChild = trim($pathArray[3]); 

这不是在D7工作了,因为仅menu_get_active_trail递送“节点/ 4” URL。如何在D7中获取上述网址?

谢谢!

+0

查看menu_get_active_trail函数页面的第一条评论。 https://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_active_trail/7 – 2pha 2014-09-02 05:36:08

回答

1

您可以使用drupal_get_path_alias()函数获取活动路径的路径别名。

$menuActive = menu_get_active_trail(); 

// Get the path alias from active trail 
$menuParent = drupal_get_path_alias($menuActive); 

$path = $menuParent[1]['page_arguments'][0]->path; 
$pathArray = explode('/', $path); 
$menuParent = $pathArray[1]; 
$menuChild = trim($pathArray[3]);