如何在Drupal中获取单击的菜单项的$mlid?
我正在尝试构建一个基于 $mlid
的子菜单。我找到了一个似乎可以完成这项工作的函数,但我似乎无法弄清楚如何获取刚刚单击的菜单项的 $mlid
。
我在 SO (http://drupal.org/node/249257< /a>),但我只能找到手动设置 $mlid 的示例。有什么建议吗?
I'm trying to build a submenu based on $mlid
. I've found a function that appears to do the job, but I just can't seem to figure out how to get the $mlid
of the menu item that was just clicked.
I found the function in a link on similar post here on SO (http://drupal.org/node/249257), but I can only find examples where the $mlid is set manually. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用
menu_get_item()
函数获取有关当前页面的信息作为菜单项,然后查询数据库以获取 mlid。注意 - 这适用于 Drupal 6。
You can use the
menu_get_item()
function to get information about the current page as a menu item, then make a query to the database to get the mlid.Note - this applies to Drupal 6.
emmychan 解决方案背后的想法很棒,但包含错误。所以我为 Drupal 7 的数据库 api 重写了它:
编辑:为了使代码片段更加通用,就像 Ambidex 建议我更新代码一样,它使用
$_GET['q']
来尝试获取 MLID当前页面。The idea behind emmychan's solution is great, but contains errors. So I rewrote it for Drupal 7's database api:
EDIT: To make the snippet more versatile like Ambidex suggests I updated the code so it uses
$_GET['q']
to try to get the MLID of the current page.我建议您使用:
menu_get_active_trail()< /code>
您将获得当前的
$mlid
。适用于 Drupal 7。
I advice you to use:
menu_get_active_trail()
You'll get the current
$mlid
.It's for Drupal 7.
这是基于 Drupal 7 的 Imeurs 代码。如果您不知道 $nid,或者将在面板页面中使用它,您可以使用以下代码获取当前项目:
This is based off of Imeurs code for Drupal 7. If you don't know the $nid, or will be using this with panels pages, you can get the current item using the following code:
您真的不是在寻找 菜单块 模块吗?
Aren't you really looking for the Menu Block module?